2016-03-25 12 views
0

私はAndroidアプリの開発にかなり新しいので、少し問題があります。LinearLayout TextViewを画面外に押し出す

私はあなたがここに見ることができるように上にのTextViewと2それでImageButtonsと別のLinearLayoutとのLinearLayoutをしている

- しかし、私はより多くのものを追加し、別のLinearLayoutを追加しようとしました

Looks pretty-ish

が、それは画面ここ

I add another LinearLayout and this happens

のうち、私のウェルカムメッセージをプッシュし始めに画面用XMLです

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:layout_weight="0.6" 
      android:id="@+id/layout_home"> 

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/scrollView" 
    > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:orientation="vertical" 
     android:paddingLeft="0dp" 
     android:paddingRight="0dp" 
     > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:measureWithLargestChild="false" 
      android:longClickable="false"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Welcome" 
       android:id="@+id/textView4" 
       android:textSize="60dp" 
       android:layout_weight="1" 
       android:layout_gravity="top"/> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="56dp" 
      android:paddingLeft="5dp" 
      android:paddingRight="5dp" 
      android:background="#5cfca1"> 

     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="5dp" 
      android:paddingRight="5dp"> 

      <ImageButton 
       android:id="@+id/whatisit" 
       android:layout_width="fill_parent" 
       android:layout_height="100dp" 
       android:layout_weight="0.5"/> 

      <ImageButton 
       android:id="@+id/contact" 
       android:layout_width="fill_parent" 
       android:layout_height="100dp" 
       android:layout_weight="0.5"/> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingRight="5dp" 
      android:paddingLeft="5dp" 
      android:paddingBottom="300dp"> 

      <ImageButton 
       android:id="@+id/howcanitreatit" 
       android:layout_width="fill_parent" 
       android:layout_height="100dp" 
       android:layout_weight="0.5"/> 

      <ImageButton 
       android:id="@+id/disclaimer" 
       android:layout_width="fill_parent" 
       android:layout_height="100dp" 
       android:layout_weight="0.5" 
       android:adjustViewBounds="false"/> 
     </LinearLayout> 

    </LinearLayout> 
</ScrollView> 

編集:のstyles.xml

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 


</style> 

私は他の質問を見てきましたが、彼らは自分のレイアウトを設定するという点で異なる多くのことを行うように見えたしましたより多くの要素などがあります。

なぜウェルカムメッセージを押し出すのですか?私はここで間違って何をしていますか?

また、何かを精査してください。私がやったよりミス、より良い

+0

なぜレイアウトの重みを追加しますか? –

+0

'style.xml'ファイルを投稿してください。 –

+0

@ ZeeshanShabbir ImageButtonsのlayout_weightは、それらを分割することです。他のものはおそらく実験の間違いでしょう – JPanda

答えて

0

LinearLayout第二):

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:orientation="vertical" 
     android:paddingLeft="0dp" 
     android:paddingRight="0dp" 
     > 

はアウトテイク:android:layout_gravity="center"

をも削除します。android:paddingBottom="300dp"を最後LinearLayout

から、それが示すようになります、しかし、ハードコーディングされたdpの値をたくさん使用していますが、これは決して本当に良い練習ではありません。

+0

すごい!それはそれを修正しました。どうもありがとうございました。私はハードコーディングされた値に取り組んでいます、誰かがすでに言及しており、私が話しているように編集しています – JPanda

+0

どちらか/両方の提案が問題を解決しました - あなたのハードコーディングされた 'dp'値は、単に適合しなかった –

+0

Dulyは指摘した。もう一度ありがとうございます:) – JPanda

0

はandroid_heightとandroid_width性質がどのように描画するか、画面を伝えるために存在し、この

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:orientation="vertical" 
    android:paddingLeft="0dp" 
    android:paddingRight="0dp" 
    > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:measureWithLargestChild="false" 
     android:longClickable="false"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Welcome" 
      android:id="@+id/textView4" 
      android:textSize="60dp" 
      android:layout_weight="1" 
      android:layout_gravity="top"/> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="56dp" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp" 
     android:background="#5cfca1"> 

    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp"> 

     <ImageButton 
      android:id="@+id/whatisit" 
      android:layout_width="fill_parent" 
      android:layout_height="100dp" 
      android:layout_weight="0.5"/> 

     <ImageButton 
      android:id="@+id/contact" 
      android:layout_width="fill_parent" 
      android:layout_height="100dp" 
      android:layout_weight="0.5"/> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingRight="5dp" 
     android:paddingLeft="5dp" 
     android:paddingBottom="300dp"> 

     <ImageButton 
      android:id="@+id/howcanitreatit" 
      android:layout_width="fill_parent" 
      android:layout_height="100dp" 
      android:layout_weight="0.5"/> 

     <ImageButton 
      android:id="@+id/disclaimer" 
      android:layout_width="fill_parent" 
      android:layout_height="100dp" 
      android:layout_weight="0.5" 
      android:adjustViewBounds="false"/> 
    </LinearLayout> 

</LinearLayout> 

+0

ありがとうございました。残念ながら、これは違いはありませんでした(同じ結果が残っています) – JPanda

0

をお試しくださいあなたのウェルカムメッセージにはfill_parentプロパティがあります。これは、基本的に画面全体に広がっていることを伝えます。それをラップcに変更しますあなたがそれを与えた高さと幅は、画面サイズよりも大きい可能性があります。また、7300以上の異なるアンドロイド携帯と一致しないため、悪い習慣もあります。 xml。 は

+0

これはほとんどのチュートリアルでは教えてくれません。このアドバイスをありがとうございました!このページをご覧になり、すぐに編集します – JPanda

0

は、それはあなたの条件で可能である場合TextViewようこそため固定高さを設定してみてくださいthisの記事をお読みくださいその詳細情報は。

E.G:コードのこの部分でandroid:layout_height="65dp"

+0

こんにちは、ありがとうございました!残念ながら、それはまだ同じ結果を持っています:https://sc-cdn.scaleengine.net/i/ced0966c2ba69294afab0839f80e6d40.png – JPanda

0

次のLOCを2番目のLinearLayoutから削除してみます。すなわち、ScrollViewの直後のLinearLayoutです。

android:layout_gravity="center" 
関連する問題