在安卓默认布局(RelativeLayout)中已经添加好好按钮,需要滚动条时如何添加?
2015-04-07 23:04
405 查看
创建好的默认布局(已经添加按钮)
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="42dp"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_centerVertical="true"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button3"
android:layout_alignLeft="@+id/button1"
android:layout_marginBottom="42dp"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_alignParentBottom="true"
android:layout_marginBottom="28dp"
android:text="Button" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_below="@+id/button3"
android:layout_marginTop="16dp"
android:text="Button" />
</RelativeLayout>
发现界面不够放下所有按钮,这时需要用到滚动条
修改代码
<ScrollView 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:overScrollMode="ifContentScrolls">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="551dp"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_alignParentBottom="true"
android:layout_marginBottom="28dp"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button5"
android:layout_alignParentRight="true"
android:layout_marginRight="92dp"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:text="Button" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button3"
android:layout_marginTop="82dp"
android:text="Button" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button4"
android:layout_below="@+id/button5"
android:layout_marginTop="86dp"
android:text="Button" />
</RelativeLayout>
</ScrollView>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="42dp"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_centerVertical="true"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button3"
android:layout_alignLeft="@+id/button1"
android:layout_marginBottom="42dp"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_alignParentBottom="true"
android:layout_marginBottom="28dp"
android:text="Button" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_below="@+id/button3"
android:layout_marginTop="16dp"
android:text="Button" />
</RelativeLayout>
发现界面不够放下所有按钮,这时需要用到滚动条
修改代码
<ScrollView 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:overScrollMode="ifContentScrolls">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="551dp"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_alignParentBottom="true"
android:layout_marginBottom="28dp"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button5"
android:layout_alignParentRight="true"
android:layout_marginRight="92dp"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:text="Button" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button3"
android:layout_marginTop="82dp"
android:text="Button" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button4"
android:layout_below="@+id/button5"
android:layout_marginTop="86dp"
android:text="Button" />
</RelativeLayout>
</ScrollView>
相关文章推荐
- 有关RelativeLayout布局中, 当一个控件被左右两个控件夹在中间时, 此控件如何靠近两个控件中的一个的问题?
- 如何让ECSHOP后台添加完商品后默认不上架 ecshop实现供应商上传产品需要审核
- 如何优化你的布局层级结构之RelativeLayout和LinearLayout及FrameLayout性能分析
- 如何优化你的布局层级结构之RelativeLayout和LinearLayout及FrameLayout性能分析
- 如何优化你的布局层级结构之RelativeLayout和LinearLayout及FrameLayout性能分析
- 安卓学习之--排版RelativeLayout表格布局
- android 使用RelativeLayout布局出现的问题汇总(不定期添加更新)
- 安卓布局之相对布局(relativeLayout)
- 安卓初学一之布局RelativeLayout和linearlayout
- 【转】CLASS ALV(CL_GUI_ALV_GRID) 添加保存布局(Save Layout)的按钮
- 在Acitvity里为RelativeLayout布局添加 view
- RelativeLayout相对布局 安卓布局技巧
- [安卓] 如何判断桌面已经添加APP应用的快捷方式
- 如何优化你的布局层级结构之RelativeLayout和LinearLayout及FrameLayout性能分析
- java:Applet布局问题,如何添加按钮,标签问题总结
- 在Acitvity里为RelativeLayout布局添加 view
- 安卓布局 - 相对布局(RelativeLayout)
- 安卓学习之线性布局LinearLayout和相对布局RelativeLayout 比较
- 如何优化你的布局层级结构之RelativeLayout和LinearLayout
- 如何优化你的布局层级结构之RelativeLayout和LinearLayout及FrameLayout性能分析