課程
/移動(dòng)開(kāi)發(fā)
/Android
/Android攻城獅的第二門課(第1季)
怎么樣才可以讓圖片滑動(dòng)到最后一張停止,我不要無(wú)限滑動(dòng)
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 就暫時(shí)可以不需要用適配器了
直接使用 HorizontalScrollView 即可!
慕UI7405811 提問(wèn)者
舉報(bào)
本課程由淺入深地帶您學(xué)會(huì)Android的常用控件的開(kāi)發(fā)和使用
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
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 就暫時(shí)可以不需要用適配器了
2016-11-19
直接使用 HorizontalScrollView 即可!