課程
/移動開發
/Android
/Android攻城獅的第二門課(第1季)
怎么樣才可以讓圖片滑動到最后一張停止,我不要無限滑動
2016-11-19
源自:Android攻城獅的第二門課(第1季) 11-2
正在回答
布局文件可以這樣:
<HorizontalScrollView ? ?android:layout_width="match_parent" ? ?android:layout_height="match_parent" ? ?android:scrollbars="none" ? ?tools:ignore="UselessParent"> ?<LinearLayout ? ? ?android:id="@+id/layout_gallery" ? ? ?android:layout_width="wrap_content" ? ? ?android:layout_height="match_parent" ? ? ?android:orientation="horizontal"> ?</LinearLayout></HorizontalScrollView>
Java 代碼可以這樣:
int[] images = {
????// 這里是圖片資源 ID 集合
};
LinearLayout gallery = (LinearLayout) findViewById(R.id.layout_gallery);for (int i = 0; i < images.length; i++) { ?gallery.addView(getImage(i));}
// 注意使用?HorizontalScrollView 就暫時可以不需要用適配器了
直接使用 HorizontalScrollView 即可!
慕UI7405811 提問者
舉報
本課程由淺入深地帶您學會Android的常用控件的開發和使用
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-11-19
布局文件可以這樣:
<HorizontalScrollView
? ?android:layout_width="match_parent"
? ?android:layout_height="match_parent"
? ?android:scrollbars="none"
? ?tools:ignore="UselessParent">
?<LinearLayout
? ? ?android:id="@+id/layout_gallery"
? ? ?android:layout_width="wrap_content"
? ? ?android:layout_height="match_parent"
? ? ?android:orientation="horizontal">
?</LinearLayout>
</HorizontalScrollView>
Java 代碼可以這樣:
int[] images = {
????// 這里是圖片資源 ID 集合
};
LinearLayout gallery = (LinearLayout) findViewById(R.id.layout_gallery);
for (int i = 0; i < images.length; i++) {
?gallery.addView(getImage(i));
}
// 注意使用?HorizontalScrollView 就暫時可以不需要用適配器了
2016-11-19
直接使用 HorizontalScrollView 即可!