如何设置两个控件在水平方向上的占屏幕的比例?
1.要有线性布局LinerLayout
2.设置线性布局控件水平排列:
android:orientation="horizontal"
3.设置第一个控件:
android:layout_width="0dp"
android:layout_weight="6"
第二个控件:
android:layout_width="0dp"
android:layout_weight="4"
这样两个控件占屏幕比例分别为6:4.
整个布局范例内容如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
tools:context=".MainActivity"
android:orientation="horizontal"
android:background="#1E90FF">
<EditText
android:id="@+id/input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6"
/>
<Button
android:id="@+id/enter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="输入"/>
</LinearLayout>
实际效果: