2017-01-17 8 views
1

LinearLayoutTextViewを追加しますが、と入力するとこのLinearLayoutが展開されます。私は本からのガイドに従っているので、それをRelativeLayoutまたはそれに変更するオプションではありません。これは私のXMLコードです:TextViewを追加するときにLinearLayoutが展開されます

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="horizontal" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="40" 
     android:background="@android:color/holo_orange_light"> 

     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent"> 

       <TextView 
        android:text="" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:id="@+id/textView" /> 
      </LinearLayout> 
     </ScrollView> 
    </LinearLayout> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="60"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:srcCompat="@mipmap/ic_launcher" 
      android:id="@+id/imageView" 
      android:layout_weight="1" /> 
    </LinearLayout> 
</LinearLayout> 
+0

勿論親を持つので、 wrap_contentはその子の幅に調整されます(子の中で最大)。 –

+0

ビューグループの通常の動作(Linearlayoutなど)は何ですか?しかし、あなたの質問は何ですか?あなたは別の行動をしたいですか? – Dibzmania

答えて

0

イムないあなたがそれをやりたい正確に何をしてください、それは「match_parent」としているのTextViewとのLinearLayoutのlayout_widthを変更してみてください。

0

TextViewの幅にテキストを追加すると、テキストが大きくなり、幅が "wrap_content"に設定され、その幅が保持するテキストの幅になるようにTextViewが拡張されます。その結果、TextViewの親ビューであるLinearLayoutは "wrap_content"に設定されているので、より大きな幅になります。その結果、ScrollViewが大きくなり、その外のLinearLayoutが大きくなるためです。

この問題を解決するには、LinearLayoutの幅を「match_parent」または任意の幅(「50dp」など)に設定します。 "match_parent"を設定する場合、LinearLayoutの幅は画面の幅になりますが、LinearLayoutsとScrollViewの両方に "match_parent"を設定する必要があります。

私はそれはあなたがのTextViewに高さを指定されている場合、あなたのコードに問題がXMLファイルには、あなたの質問

0

に答え願っています:

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_weight="40" 
    android:background="@android:color/holo_orange_light"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent"> 
     <!--Change your textView as below--> 
      <TextView 
       android:text="" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/textView" /> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 
<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_weight="60"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:srcCompat="@mipmap/ic_launcher" 
     android:id="@+id/imageView" 
     android:layout_weight="1" /> 
</LinearLayout> 

関連する問題