本篇记录RelativeLayout中实现权重效果
先上效果图
然后上布局文件,根据代码来说
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="@drawable/style_alert_dialog_addplayer">
<EditText
android:id="@+id/et_addPlayerName"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_marginEnd="50dp"
android:background="@drawable/style_edittext_round_bg"
android:inputType="text" />
<Button
android:id="@+id/btn_addPlayer"
android:layout_width="50dp"
android:layout_height="120dp"
android:layout_alignParentEnd="true"
android:background="@null"
android:text="@string/add"
android:textColor="@color/colorAccent" />
</RelativeLayout>
在布局文件中,我们先设置了外层的RelativeLayout的高宽,通过Button来撑起他的高度。
然后Button通过和父布局的右边对齐 android:layout_alignParentEnd="true"
然后在要实现权重的控件EditText上设置 **android:layout_width=“fill_parent”**就可以了
简单记录下。
参考了这篇文章
RelativeLayout的自适应