如何在视图组边缘和视图边缘之间获取dp(s),如下图中标记的红色箭头?
这是我的布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/ll_select_gander"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".4"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="@dimen/margin_padding_double_standard">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/select_male_not_selected"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:text="@string/male"
android:textColor="@color/color_white"
android:textStyle="bold"
android:gravity="center"
android:textSize="@dimen/medium_text"
android:paddingTop="@dimen/margin_padding_standard"
android:paddingBottom="@dimen/margin_padding_standard"
android:layout_marginTop="@dimen/margin_padding_double_standard"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="@dimen/margin_padding_double_standard">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/select_female_not_selected"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:text="@string/female"
android:textColor="@color/color_white"
android:textStyle="bold"
android:gravity="center"
android:textSize="@dimen/medium_text"
android:paddingTop="@dimen/margin_padding_standard"
android:paddingBottom="@dimen/margin_padding_standard"
android:layout_marginTop="@dimen/margin_padding_double_standard"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_ribon"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1"
android:background="@color/ribbon_color"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/margin_padding_double_standard"
android:text="@string/date_of_birth"
android:textColor="@color/theme_nevy_blue"
android:textSize="@dimen/large_text" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_select_dob"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".4"
android:orientation="vertical">
</LinearLayout>
答案 0 :(得分:0)
您可以将android:layout_weight="1"
和android:gravity="right"
添加到第一个(左侧)LinearLayout,并将android:layout_weight="1"
和android:gravity="left"
添加到第二个(右侧)LinearLayout以归档类似的结果。
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_select_gander"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".4"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin_padding_double_standard"
android:layout_weight="1"
android:gravity="left"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/select_male_not_selected" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_padding_double_standard"
android:background="@color/colorPrimary"
android:gravity="center"
android:paddingBottom="@dimen/margin_padding_standard"
android:paddingTop="@dimen/margin_padding_standard"
android:text="@string/male"
android:textColor="@color/color_white"
android:textSize="@dimen/medium_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_padding_double_standard"
android:layout_weight="1"
android:gravity="left"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/select_female_not_selected" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_padding_double_standard"
android:background="@color/colorPrimary"
android:gravity="center"
android:paddingBottom="@dimen/margin_padding_standard"
android:paddingTop="@dimen/margin_padding_standard"
android:text="@string/female"
android:textColor="@color/color_white"
android:textSize="@dimen/medium_text"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_ribon"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1"
android:background="@color/ribbon_color"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/margin_padding_double_standard"
android:text="@string/date_of_birth"
android:textColor="@color/theme_nevy_blue"
android:textSize="@dimen/large_text" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_select_dob"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".4"
android:orientation="vertical">
</LinearLayout>