这里我主要实现这样一个布局,左侧文字,右侧2个按钮。
效果如下图:
配置文件如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左边文字"
android:layout_gravity="center_vertical"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="button1"
android:drawableLeft="@mipmap/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="button1"
android:drawableLeft="@mipmap/button"/>
</LinearLayout>
</LinearLayout>
整体采用水平 LinearLayout,左边就是一个textview, 右边再采用一个水平的LinearLayout ,设置长度铺满剩余空间,然后设置容器内容向右对齐。
思路很简单,刚做项目时写了很久,特意记录一下。