2017-03-06 11 views
-2

私はちょうどid rl1の相対レイアウトを作成しました。私はこの相対レイアウトに対して2を使ってweightSumを作成したいと思います。このレイアウトを置く別の2つの相対レイアウト1とfireID相対レイアウトcartIDは、それらのそれぞれが重み1を取るどのどのように私はこの問題に をスィルヴすることができ、これは私のxmlファイル我々はRelativeLayoutで重量を使用することはできませんRelativeLayoutでweightSumを使用する方法

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    tools:context="abtech.waiteriano.com.waitrer.MenuActivity"> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:minHeight="?attr/actionBarSize" /> 
    <!-- <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="matc 
     h_parent" 
     android:layout_height="wrap_content"></FrameLayout>--> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="bottom" 
     android:id="@+id/rl1" 
     android:orientation="horizontal" 
     android:weightSum="2"> 
     <FrameLayout 
      android:id="@+id/content_frame" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/fireID"> 
     </FrameLayout> 

     <RelativeLayout 
      android:id="@+id/fireID" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:layout_weight="1" 
      android:background="#ff6b6b" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentStart="true"> 
      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:layout_gravity="center" 
       android:src="@drawable/fire" /> 
     </RelativeLayout> 
     <RelativeLayout 
      android:id="@+id/cartID" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:layout_weight="1" 
      android:background="#ff6b6b" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentStart="true"> 
      <ImageView 
       android:id="@+id/imageCart" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:layout_gravity="center" 
       android:src="@drawable/shoppingcart" /> 
     </RelativeLayout> 
    </RelativeLayout> 
</LinearLayout> 
+0

この... http://stackoverflow.com/questions/21144691/alternative-to-weightsum-in-relativelayout –

+3

を参照してください。このプロパティはLinearLayoutでのみ使用します –

+0

最初の 'RelativeLayout'を' LinearLayout'に置き換えます –

答えて

4

です。

+0

私は実際にそれを知っていますが、これを線形レイアウトに変更すると、この線形レイアウトがレイアウトを含むページの最下部に表示されるので、 @Asif Patel –

+0

idのfireIdとcartIdのRelativeLayoutを削除し、alignParentBottom属性でLinearLayoutを作成し、2つのImageViewをその中に配置します。各ImageViewの重みは1です。 –

0

私はすべてに感謝を必要とする実際に何がある....

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    tools:context="abtech.waiteriano.com.waitrer.MenuActivity"> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:minHeight="?attr/actionBarSize" /> 
    <!-- <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="matc 
     h_parent" 
     android:layout_height="wrap_content"></FrameLayout>--> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="bottom" 
     android:id="@+id/rl1" 
     android:orientation="horizontal" 
     android:weightSum="2"> 
     <FrameLayout 
      android:id="@+id/content_frame" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/bottom_panel"> 
     </FrameLayout> 

     <LinearLayout 
      android:id="@+id/bottom_panel" 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:weightSum="2" 
      android:layout_alignParentBottom="true"> 
      <RelativeLayout 
       android:id="@+id/fireID" 
       android:layout_width="fill_parent" 
       android:layout_height="50dp" 
       android:layout_weight="1" 
       android:background="#ff6b6b" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentStart="true"> 
       <ImageView 
        android:id="@+id/imageView1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 
        android:layout_gravity="center" 
        android:src="@drawable/fire" /> 
      </RelativeLayout> 
      <RelativeLayout 
       android:id="@+id/cartID" 
       android:layout_width="fill_parent" 
       android:layout_height="50dp" 
       android:layout_weight="1" 
       android:background="#ff6b6b" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentStart="true"> 
       <ImageView 
        android:id="@+id/imageCart" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 
        android:layout_gravity="center" 
        android:src="@drawable/shoppingcart" /> 
      </RelativeLayout> 
     </LinearLayout> 
    </RelativeLayout> 
</LinearLayout> 
関連する問題