日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android控制滚动条滚动

發(fā)布時間:2025/3/21 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android控制滚动条滚动 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

android控制滾動條滾動

運行結果:


主Activity:

public class MainActivity extends Activity {

private RelativeLayout topbar;

private RelativeLayout scroll;

private LayoutInflater inflater;

private LinearLayout topbarLinea;

private LinearLayout scrollLinea;

private Button lastButton;

private Button nextButton;

View v1;

HorizontalScrollView v2;

LinearLayout v3;


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

inflater = LayoutInflater.from(this);

topbar = (RelativeLayout)inflater.inflate(R.layout.topbar, null);

scroll = (RelativeLayout)inflater.inflate(R.layout.hscroll_bar, null);

topbarLinea = (LinearLayout)findViewById(R.id.topbar_linea);

scrollLinea = (LinearLayout)findViewById(R.id.scroll_linea);

lastButton = (Button)findViewById(R.id.the_last);

nextButton = (Button)findViewById(R.id.the_next);

topbarLinea.addView(topbar);

scrollLinea.addView(scroll);

v2 = (HorizontalScrollView)scroll.findViewById(R.id.hscroll_bar);

v3 = (LinearLayout)scroll.findViewById(R.id.content_linea);

addLastListener();

addNextListener();

// WindowManager manage=getWindowManager();

// ? ? Display display=manage.getDefaultDisplay();

// ? ? screenHeight=display.getHeight();

// ? ? screenWidth=display.getWidth();

}

public void addLastListener(){

lastButton.setOnClickListener(new OnClickListener() {


@Override

public void onClick(View v) {

v2.smoothScrollTo(v2.getScrollX() - 100, 0);

}

});

}

public void addNextListener(){

nextButton.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

v2.smoothScrollTo(v2.getScrollX() + 100, 0);

}

});

}

}

主布局文件:

<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"

? ? tools:context=".MainActivity" >


? ? <LinearLayout android:id="@+id/topbar_linea"

? ? ? ? android:layout_width="fill_parent"

? ? ? ? android:layout_height="wrap_content">

?? ? ? ?

? ? </LinearLayout>

?? ?

? ? <LinearLayout android:id="@+id/scroll_linea"

? ? ? ? android:layout_width="fill_parent"

? ? ? ? android:layout_height="wrap_content"

? ? ? ? android:layout_below="@id/topbar_linea"

? ? ? ? android:layout_marginTop="20dp">

?? ? ? ?

? ? </LinearLayout>

?? ?

? ? <RelativeLayout android:layout_width="fill_parent"

? ? ? ? android:layout_height="wrap_content"

? ? ? ? android:layout_marginTop="30dp"

? ? ? ? android:layout_below="@id/scroll_linea">

?? ? ? ?

? ? ? ? <Button android:id="@+id/the_last"

? ? ? ? ? ? android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:textSize="18sp"

? ? ? ? ? ? android:text="上一個"

? ? ? ? ? ? android:layout_alignParentLeft="true"

? ? ? ? ? ? android:layout_marginLeft="20dp"/>

? ? ? ? <Button android:id="@+id/the_next"

? ? ? ? ? ? android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:textSize="18sp"

? ? ? ? ? ? android:text="下一個"

? ? ? ? ? ? android:layout_alignParentRight="true"

? ? ? ? ? ? android:layout_marginRight="20dp"/>

? ? </RelativeLayout>

</RelativeLayout>

滾動條布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

? ? xmlns:tools="http://schemas.android.com/tools"

? ? android:layout_width="fill_parent"

? ? android:layout_height="wrap_content"

? ? tools:context=".MainActivity" >


? ? <HorizontalScrollView?

? ? ? ? android:id="@+id/hscroll_bar"

? ? ? ? android:layout_width="wrap_content"

? ? ? ? android:layout_height="wrap_content"

? ? ? ? android:scrollbars="none">

?? ? ? ?

?? ? ? ? <LinearLayout android:id="@+id/content_linea"

? ? ? ? ? ? android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content">

?? ? ? ?

? ? ? ? <TextView android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:text="北京1"

? ? ? ? ? ? android:textSize="18sp"

? ? ? ? ? ? android:layout_marginLeft="10dp"

? ? ? ? ? ? android:layout_marginRight="10dp"/>

? ? ? ? <TextView android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:text="北京2"

? ? ? ? ? ? android:textSize="18sp"

? ? ? ? ? ? android:layout_marginLeft="10dp"

? ? ? ? ? ? android:layout_marginRight="10dp"/>

? ? ? ? <TextView android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:text="北京3"

? ? ? ? ? ? android:textSize="18sp"

? ? ? ? ? ? android:layout_marginLeft="10dp"

? ? ? ? ? ? android:layout_marginRight="10dp"/>

? ? ? ? <TextView android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:text="北京4"

? ? ? ? ? ? android:textSize="18sp"

? ? ? ? ? ? android:layout_marginLeft="10dp"

? ? ? ? ? ? android:layout_marginRight="10dp"/>

? ? ? ? <TextView android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:text="北京5"

? ? ? ? ? ? android:textSize="18sp"

? ? ? ? ? ? android:layout_marginLeft="10dp"

? ? ? ? ? ? android:layout_marginRight="10dp"/>

? ? ? ? <TextView android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:text="北京6"

? ? ? ? ? ? android:textSize="18sp"

? ? ? ? ? ? android:layout_marginLeft="10dp"

? ? ? ? ? ? android:layout_marginRight="10dp"/>

? ? ? ? <TextView android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:text="北京7"

? ? ? ? ? ? android:textSize="18sp"

? ? ? ? ? ? android:layout_marginLeft="10dp"

? ? ? ? ? ? android:layout_marginRight="10dp"/>

? ? ? ? <TextView android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:text="北京8"

? ? ? ? ? ? android:textSize="18sp"

? ? ? ? ? ? android:layout_marginLeft="10dp"

? ? ? ? ? ? android:layout_marginRight="10dp"/>

? ? ? ? <TextView android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:text="北京9"

? ? ? ? ? ? android:textSize="18sp"

? ? ? ? ? ? android:layout_marginLeft="10dp"

? ? ? ? ? ? android:layout_marginRight="10dp"/>

? ? ? ? <TextView android:layout_width="wrap_content"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:text="北京10"

? ? ? ? ? ? android:textSize="18sp"

? ? ? ? ? ? android:layout_marginLeft="10dp"

? ? ? ? ? ? android:layout_marginRight="10dp"/>

? ? ? ? </LinearLayout>

? ? </HorizontalScrollView>

</RelativeLayout>

topbar布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

? ? xmlns:tools="http://schemas.android.com/tools"

? ? android:layout_width="fill_parent"

? ? android:layout_height="wrap_content"

? ? tools:context=".MainActivity" >


? ? <TextView

? ? ? ? android:layout_width="fill_parent"

? ? ? ? android:layout_height="wrap_content"

? ? ? ? android:text="topBar"

? ? ? ? android:gravity="center"

? ? ? ? android:textSize="20sp" />

</RelativeLayout>


demo下載地址:

http://download.csdn.net/download/lyhdream/5210462





《新程序員》:云原生和全面數(shù)字化實踐50位技術專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的android控制滚动条滚动的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 中文字幕精品久久久久人妻红杏ⅰ | 亚洲国产视频网站 | 久久爱综合网 | 欧美一级免费大片 | 四虎永久免费地址 | 日韩三级一区二区 | av片国产| 国产精品入口66mio男同 | 色欧美色 | 国产乱国产乱老熟300部视频 | 男女涩涩| 三级欧美日韩 | 天天操天天操天天干 | 女生张开腿给男生桶 | 成人午夜毛片 | 日日操操| 国产精品后入内射日本在线观看 | 美女国产视频 | 国产宾馆自拍 | 亚洲免费av网 | 熟女少妇一区二区 | 国产无玛| 日韩男女视频 | 男人天堂视频网 | 久草免费福利视频 | 欧美一级黑人 | 日本在线天堂 | va欧美| 亚洲色图在线播放 | 中文字幕无码乱人伦 | a一级黄色 | 免费成人深夜夜行网站视频 | 最新极品jizzhd欧美 | 麻豆精品在线看 | 91手机在线 | 色婷婷综合五月 | 日p视频在线观看 | 97一级片| 成人免费视频免费观看 | www.四虎精品 | aaaaa级少妇高潮大片免费看 | 欧美高清另类 | 成人啪啪18免费游戏链接 | 久久久久久久久成人 | 国产77777| 美女扒开腿让男人操 | 国产91精品一区二区绿帽 | 香蕉视频在线免费播放 | 国产精品性色 | 欧美一区二区视频免费观看 | 日韩无码专区 | 国产精品1 | 欧美成人三级在线视频 | 国产日韩欧美中文 | 久久日本精品字幕区二区 | 午夜免费高清视频 | 北条麻妃二三区 | 一本大道东京热无码aⅴ | αv在线 | 女王人厕视频2ⅴk | 亚洲伦理精品 | 黄色片aaa| 国产色在线,com | 91色视频在线观看 | 免费av成人 | 噜噜噜av | 极品尤物在线观看 | 人妻无码一区二区三区久久99 | 香蕉视频免费在线 | 日产精品久久久 | 中国在线观看免费视频 | 182tv午夜 | 国产污污视频在线观看 | 岛国福利视频 | 亚洲 欧美 综合 | 中文字幕精品一二三四五六七八 | av大片免费观看 | 99精品国产成人一区二区 | 永久免费快色 | 国产精品第7页 | 免费视频久久 | 中文字幕在线视频播放 | 蜜臂av | 免费看h网站 | 国产无精乱码一区二区三区 | 四虎精品视频 | 午夜肉伦伦影院 | 能看的毛片 | 欧美一级欧美三级在线观看 | 无套暴操 | 毛片9| 性――交――性――乱睡觉 | 女人高潮被爽到呻吟在线观看 | 94av| 国产中文字幕免费 | 人妻夜夜爽天天爽 | 黄av网| 国产精品免费一区二区三区都可以 | www.av网 |