Android第三次(layout——02)

  1. 相对布局(重点)
    1.1 相对布局窗口内子组件的位置总是相对兄弟组件、父容器来决定的,因此叫相对布局

1.2 如果A组件位置是由B组件的位置决定的,Android要求先定B组件,再定义A组件
如果A组件位置是由B组件的位置决定的,Android要求先定B组件,再定义A组件
如果A组件位置是由B组件的位置决定的,Android要求先定B组件,再定义A组件

1.3 id型
@+id和@id的区别
@+id/x1(添加新ID)____android:id="@+id/but_main_blue"

      @id/x1(引用此ID)___android:layout_toRightOf="@id/but_main_blue"

      相对于指定元素(根据ID指定)
  1. 网格布局
    2.1 常用属性
    GridLayout布局相关属性:rowCount、columnCount
    GridLayout中子控件相关属性:layout_gravity=“fill_horizontal|fill_vertical”

2.2 Space标签的作用:挡住控件,让其不超出网格的范围

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Android应用开发过程中,有时候我们需要实现全屏滚动的效果,或者在滚动页面中嵌入ListView等组件。下面就来介绍一下如何实现这些效果。 一、全屏滚动 实现全屏滚动需要用到Android系统提供的ScrollView组件。ScrollView可以包含多个子视图,并且可以在垂直方向上进行滚动。下面是一个简单的例子: ``` <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第一行"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第二行"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第三行"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第四行"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第五行"/> </LinearLayout> </ScrollView> ``` 上面的代码中,我们将ScrollView作为根布局,然后在ScrollView内部添加了一个垂直方向的LinearLayout,这个LinearLayout包含了多个TextView,每个TextView显示一行文本。运行这个应用,可以看到整个页面可以在垂直方向上滚动。 二、在滚动页面中嵌入ListView 有时候我们需要在滚动页面中嵌入ListView,这时候可以使用Android系统提供的NestedScrollView组件。NestedScrollView是ScrollView的子类,可以包含多个子视图,并且可以在垂直方向上进行滚动。和ScrollView不同的是,NestedScrollView可以嵌套其他可滚动的组件,例如ListView等。 下面是一个简单的例子: ``` <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第一行"/> <ListView android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="@null" android:dividerHeight="0dp" android:scrollbars="none"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第三行"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第四行"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是第五行"/> </LinearLayout> </android.support.v4.widget.NestedScrollView> ``` 上面的代码中,我们将NestedScrollView作为根布局,然后在NestedScrollView内部添加了一个垂直方向的LinearLayout。这个LinearLayout包含了多个TextView和一个ListView。由于ListView也可以滚动,所以我们需要将它的滚动条隐藏掉,然后就可以在滚动页面中嵌入ListView了。 以上就是Android开发中如何实现全屏滚动和在滚动页面中嵌入ListView的方法。希望对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值