2016-04-03 4 views
0

私のレイアウトはFigure.soに示すようにしたいweightsum.butデザインを使用しています。実際のレイアウトと背景色を除いて表示されません。 weightSum属性がLinearLayout内で宣言されなければならない私0dpを設定してもweightsumが動作しない

enter image description here

xmlファイル内のコード

<RelativeLayout 
    android:weightSum="100" 
    android:background="#C5C5C5" 
    android:layout_height="60dp" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent"> 
    <LinearLayout 

     android:layout_weight="45" 
     android:id="@+id/signinBtn" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:background="@drawable/rounded_corner"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Sign In" 
      android:gravity="center" 
      android:padding="5dp" /> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_weight="10" 
     android:layout_width="00dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/signinBtn" /> 
    <LinearLayout 
     android:layout_weight="45" 
     android:id="@+id/cancelBtn" 
     android:layout_width="00dp" 
     android:layout_height="wrap_content" 
     android:background="@drawable/rounded_corner"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Cancel" 
      android:gravity="center" 
      android:padding="5dp" /> 
    </LinearLayout> 
</RelativeLayout> 
+0

最初のものは、あなたが 'weightsumを使用していないですのような重量を使用する線形レイアウトする必要があります'どこで、なぜあなたは' android:layout_weight'でこのような大きな値を使用していますか? –

+0

あなたは完全に重量の概念を台無しにしました。 weightsum属性を持つビューの幅は0dpではありませんが、その子は –

+0

です残りの部分は10です。 –

答えて

0

あなたの親のレイアウトはすべて、この

<LinearLayout 
android:weightSum="100" 
android:background="#C5C5C5" 
android:layout_height="60dp" 
android:orientation="horizontal" 
android:layout_width="fill_parent"> 
<LinearLayout 
android:layout_weight="45" 
android:id="@+id/signinBtn" 
android:layout_width="0dp" 
android:layout_height="wrap_content" 
android:background="@drawable/rounded_corner"> 
<TextView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Sign In" 
android:gravity="center" 
android:padding="5dp" /> 
</LinearLayout> 
<LinearLayout 
android:layout_weight="10" 
android:layout_width="0dp" 
android:layout_height="wrap_content" 
android:id="@+id/signinBtn" /> 
<LinearLayout 
android:layout_weight="45" 
android:id="@+id/cancelBtn" 
android:layout_width="0dp" 
android:layout_height="wrap_content" 
android:background="@drawable/rounded_corner"> 
<TextView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Cancel" 
android:gravity="center" 
android:padding="5dp" /> 
</LinearLayout> 
</LinearLayout> 
1
  1. 助けます。
  2. orientationも提供する必要があります。
  3. あなたの場合、向きはhorizontalです。したがって、すべての子供は0dpの幅を持たなければなりません。
  4. LinearLayoutの各子にandroid:layout_weight属性を追加することを忘れないでください。

だから私は、次のようにレイアウトを変更するお勧め:

<LinearLayout 
     android:id="@+id/signinBtn" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:background="@drawable/rounded_corner" 
     android:orientation="horizontal" 
     android:weightSum="2"> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Sign In" 
      android:gravity="center" 
      android:padding="5dp" /> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Cancel" 
      android:gravity="center" 
      android:padding="5dp" /> 
</LinearLayout> 
関連する問題