2

私は android:weight 属性を使用しています。

最初の状態

http://s1.postimg.org/umygk8han/first.png

<LinearLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="223"
      android:orientation="horizontal" >
   </LinearLayout>

TextViewを追加する場合

http://s7.postimg.org/89qjb42dn/two.png

 <LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="223"
    android:orientation="horizontal" >

    <TextView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:text="Sample"
      android:textColor="@android:color/background_dark" />
  </LinearLayout>

どうすればこの問題を解決できますか?

よろしくお願いします

4

4 に答える 4

0

以下のコードを使用してみてください。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:orientation="vertical"
    android:padding="5dip"
    android:weightSum="2" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="@android:color/white"
        android:text="Sample" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:orientation="vertical"
    android:padding="5dip"
    android:weightSum="2" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="@android:color/white"
        android:text="Sample"
        android:textColor="@android:color/background_dark" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:orientation="vertical"
    android:padding="5dip"
    android:weightSum="2" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="@android:color/white"
        android:text="Sample"
        android:textColor="@android:color/background_dark" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:orientation="vertical"
    android:padding="5dip"
    android:weightSum="2" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="@android:color/white"
        android:text="Sample"
        android:textColor="@android:color/background_dark" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:orientation="vertical"
    android:padding="5dip"
    android:weightSum="2" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="@android:color/white"
        android:text="Sample" />
</LinearLayout>

于 2013-06-14T08:34:12.447 に答える
0

にlayout_weightを割り当てるのは良い考えではないと思うので、最初はのRelativeLayout外側が 必要だと思います。LinearLayoutLinearLayout

したがって、次のようにします。

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="223"
    android:orientation="horizontal" >

    <TextView
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:text="Sample"
       android:maxLines="1"
       android:textColor="@android:color/background_dark" /> 
</RelativeLayout>

PS: を設定したandroid:layout_height="0dp"のは、 (スクリーンショットによると) のノードであるとRelativeLayout思われたためです。LinearLayourorientation='vertical'

于 2014-07-09T09:44:19.530 に答える
0

textView のフォント サイズが原因で linearlayout が拡大することを理解しています。フォント サイズを小さくしてみてください。

<TextView ....    
  android:textSize="9sp" />

また、パディング textview を 0 に設定することもできます

 android:padding="0dp"

それが役に立てば幸い!

于 2013-06-14T08:16:25.917 に答える