Android 具有相同宽度和高度的视图
在androidstudio中有没有一种简单的方法来创建如下所示的xml布局?我是iOS XCode的家伙,在那里使用比率约束做这件事没有问题 到目前为止,我正在使用带有百分比选项的Android 具有相同宽度和高度的视图,android,layout,view,constraints,Android,Layout,View,Constraints,在androidstudio中有没有一种简单的方法来创建如下所示的xml布局?我是iOS XCode的家伙,在那里使用比率约束做这件事没有问题 到目前为止,我正在使用带有百分比选项的ConstraintLayout和垂直gridlines。但这只给了我相等的宽度view1和view2,没有高度 我知道如何覆盖测量方法解决方案上的,但我想避免它 a --------------------------- | | |
ConstraintLayout
和垂直gridlines
。但这只给了我相等的宽度view1和view2,没有高度
我知道如何覆盖测量方法解决方案上的,但我想避免它
a
---------------------------
| |
| |
| |
| |
| b b |
| ----------- ----------- |
| | view1 | | view2 | |
| |b | |b | |
| | | | | |
| ----------- ----------- |
---------------------------
b = 50% * a;
您可以这样做:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageview1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/imageview2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
ImageView view_instance1 = (ImageView)findViewById(R.id.imageView1);
ImageView view_instance2 = (ImageView)findViewById(R.id.imageView2);
LinearLayout.LayoutParams params=(LinearLayout.LayoutParams)view_instance1 .getLayoutParams();
params.height= params.width;
view_instance1 .setLayoutParams(params);
view_instance2 .setLayoutParams(params);