FrameLayout 帧布局
帧布局不常用,所有控件都会摆在左上角。
示例代码
activity_frame_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".chapter03.FrameLayoutActivity"
android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_rela_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:textAllCaps="false"
android:layout_gravity="left"/>
<Button
android:id="@+id/btn_rela_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:textAllCaps="false"
android:layout_gravity="right"/>
</FrameLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
FrameLayoutActivity.java
public class FrameLayoutActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frame_layout);
}
}
网友评论