android基础 [超级详细android常用控件解析(ScollView控件,ProgressBar进度条,PopupWindow控件)]

目录

1 章节目录

2 ScollView控件

2.1 ScrollView简介

2.2 ScrollView使用

2.3 常用属性及方法

3 ProgressBar进度条

3.1 简介

3.2 常用属性

3.3 常用方法

3.4 简单的使用

4 PopupWindow控件

4.1 常用方法

4.2 创建流程:

4.3 PopupWindow的配置参数详解


1 章节目录

  • ScollView控件

  • ProgressBar进度条

  • PopupWindow控件

2 ScollView控件

2.1 ScrollView简介

  • ScrollView就是可以滚动的用户布局容器

  • 如果手机显示不下子布局,那么可以使用scrollView

2.2 ScrollView使用

  • 不要在scrollView中添加RecyclerView或者是ListView布局,这样会引起不好的体验因为会有滑动冲突的问题出现。

  • ScrollView的直接子View只能有一个。也就是说如果你要在滚动视图中添加多个视图,你需要一个标准的容器,如LinearLayoutRelativeLayout

<?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=".MainActivity">
​
    <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:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Hello World1" />
​
            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Hello World2" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>
  • ScrollView只支持竖直滑动,想要水平滑动需要使用HorizontalScrollView

<?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"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical" >
        </LinearLayout>
    </HorizontalScrollView>
</LinearLayout>

2.3 常用属性及方法

可以直接利用ScrollView给我们提供的:fullScroll()方法:

scrollView.fullScroll(ScrollView.FOCUS_DOWN);滚动到底部
scrollView.fullScroll(ScrollView.FOCUS_UP);滚动到顶部
​
隐藏滑块:  

android:scrollbars="none" 
 
设置滚动速度:
继承ScrollView,然后重写一个 public void fling (int velocityY)的方法:
@Override
public void fling(int velocityY) {
  super.fling(velocityY / 2);   //速度变为原来的一半
}
public class ScrollViewActivity extends AppCompatActivity implements
View.OnClickListener {
  private Button btn_down;
  private Button btn_up;
  private ScrollView scrollView;
  private TextView txt_show;
  @Override
  public void onCreat
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值