我的LinearLayout
有一定的方格空间。在此LinearLayout
中,我有RelativeLayout
,其高度和宽度为100dp
。此RelativeLayout
具有圆形可绘制形状。我想将RelativeLayout
的高度和宽度设置为其父LinearLayout
可用总空间的60%。有没有办法做到这一点?
这是我的一个圆形视图的xml代码片段
<RelativeLayout
android:id="@+id/rl_hatchback"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rl_hatchback_circle"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/circle_red"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_hatchback"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl_hatchback_circle"
android:text="Hatchback"
style="@style/CircularTitle"
/>
</LinearLayout>
答案 0 :(得分:0)
您可以使用PercentRelativeLayout或ConstraintLayout来减少嵌套视图的数量。 供参考:
PercentRelativeLayout: https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html
<强> ConstraintLayout:强> https://developer.android.com/training/constraint-layout/index.html