问题
I just Created a Relative Layout with id rl1 What I need I want to create a weightSum with 2 for this relative layout as to put in this layout another 2 relative layout one with id fireID and the other relative layout cartID which each of them take a weight 1 how can I silve this issue this is my xml file
<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>
回答1:
We can't use Weight in RelativeLayout
.
来源:https://stackoverflow.com/questions/42626126/how-to-use-weightsum-in-relativelayout