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

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

Gridview高度被裁剪

Gridview高度被裁剪

翻閱古今 2019-07-16 16:30:44
Gridview高度被裁剪我試圖在一個(gè)網(wǎng)格視圖中顯示8個(gè)項(xiàng)目??杀氖?,網(wǎng)格視圖的高度總是太小,所以它只顯示第一行,以及第二行的一小部分。設(shè)置android:layout_height="300dp"讓它發(fā)揮作用。包裹c(diǎn)ontent和fill_parent顯然不是。我的網(wǎng)格視圖:<GridView     android:id="@+id/myId"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:gravity="center"     android:horizontalSpacing="2dp"     android:isScrollContainer="false"     android:numColumns="4"     android:stretchMode="columnWidth"     android:verticalSpacing="20dp" />我的物品資源:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:orientation="vertical"     android:minHeight="?android:attr/listPreferredItemHeight" >     <ImageView         android:id="@+id/appItemIcon"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:src="@android:drawable/ic_dialog_info"         android:scaleType="center" />           <TextView         android:id="@+id/appItemText"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:text="My long application name"         android:gravity="center_horizontal"         android:textAppearance="?android:attr/textAppearanceSmall" /></LinearLayout>這個(gè)問題似乎與缺乏垂直空間無(wú)關(guān)。我能做什么?
查看完整描述

3 回答

?
慕尼黑的夜晚無(wú)繁華

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

另一種對(duì)我有用的類似方法是計(jì)算一行的高度,然后使用靜態(tài)數(shù)據(jù)(您可以將其調(diào)整為分頁(yè)),您可以輕松地計(jì)算出有多少行并調(diào)整GridView高度的大小。

    private void resizeGridView(GridView gridView, int items, int columns) {
    ViewGroup.LayoutParams params = gridView.getLayoutParams();
    int oneRowHeight = gridView.getHeight();
    int rows = (int) (items / columns);
    params.height = oneRowHeight * rows;
    gridView.setLayoutParams(params);}

在設(shè)置適配器和繪制GridView之后使用此代碼,否則將獲得高度=0。

gridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                if (!gridViewResized) {
                    gridViewResized = true;
                    resizeGridView(gridView, numItems, numColumns);
                }
            }
        });


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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