第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

ScrollView中的圖像網(wǎng)格

ScrollView中的圖像網(wǎng)格

不負(fù)相思意 2019-09-19 14:35:17
我正在嘗試創(chuàng)建一個(gè)包含文本和圖像的屏幕。我希望圖像像網(wǎng)格一樣布局,如下所示,但我希望它們沒(méi)有周?chē)鶶crollView提供的滾動(dòng)功能。圖像最能說(shuō)明我的問(wèn)題:<ScrollView>    <LinearLayout>        <ImageView />        <TextView />        <GridView />        <TextView />    </LinearLayout></ScrollView>什么是顯示不同數(shù)量圖像的網(wǎng)格的最佳方法,其中網(wǎng)格沒(méi)有滾動(dòng)功能?請(qǐng)注意,禁用GridView的滾動(dòng)功能不起作用,因?yàn)檫@只會(huì)禁用滾動(dòng)條但不顯示所有項(xiàng)目。更新:下圖顯示了在GridView中禁用滾動(dòng)條的情況。
查看完整描述

3 回答

?
泛舟湖上清波郎朗

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超3個(gè)贊

你有2個(gè)解決方案:


編寫(xiě)自己的自定義布局。這將是更難的解決方案(但可能被認(rèn)為是正確的解決方案)。


GridView在代碼中設(shè)置您的實(shí)際高度。例如:


  RelativeLayout.LayoutParams lp =(RelativeLayout.LayoutParams)myGridView.getLayoutParams();

  // lp.setMargins(0,0,10,10); //如果你有布局邊距,你也必須設(shè)置它們

  lp.height = measureRealHeight(...);

  myGridView.setLayoutParams(LP);

該measureRealHeight()方法應(yīng)該看起來(lái)像這樣(希望我做對(duì)了):


private int measureRealHeight(...)

{

  final int screenWidth = getWindowManager().getDefaultDisplay().getWidth();

  final double screenDensity = getResources().getDisplayMetrics().density;

  final int paddingLeft = (int) (X * screenDensity + 0.5f); // where X is your desired padding

  final int paddingRight = ...;

  final int horizontalSpacing = (int) (X * screenDensity + 0.5f); // the spacing between your columns

  final int verticalSpacing = ...; // the spacing between your rows

  final int columnWidth = (int) (X * screenDensity + 0.5f);             

  final int columnsCount = (screenWidth - paddingLeft - paddingRight + horizontalSpacing - myGridView.getVerticalScrollbarWidth()) / (columnWidth + horizontalSpacing);

  final int rowsCount = picsCount / columnsCount + (picsCount % columnsCount == 0 ? 0 : 1);


  return columnWidth * rowsCount + verticalSpacing * (rowsCount - 1);

}

上面的代碼應(yīng)該適用于A(yíng)ndroid 1.5+。


查看完整回答
反對(duì) 回復(fù) 2019-09-19
  • 3 回答
  • 0 關(guān)注
  • 607 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)