簡體   English   中英

Android Grid View定位

[英]Android Grid View positioning

在我的應用程序中,有一個網格視圖,其中包含從A到Z的字母,每當我將我的應用程序安裝在某些大尺寸屏幕手機上時,網格視圖的位置就會根據屏幕尺寸而變化。 我在大屏幕手機和小屏幕手機上都遇到了這個問題,與普通屏幕相比,該位置非常好,我需要為網格視圖編寫哪些屬性,以匹配所有屏幕尺寸而不會流動或滾動,謝謝提前

 <GridView
 android:id="@+id/letters"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:layout_gravity="center"
 android:layout_marginTop="250sp"
 android:horizontalSpacing="5sp"
 android:numColumns="9"
 android:padding="5sp"
 android:stretchMode="columnWidth"
 android:verticalSpacing="5sp" />

網格視圖參數應為
android:layout_width="fill_parent" android:layout_height="fill_parent"

我不知道我是否清楚地理解了您的問題,但如果要使網格視圖適合所有屏幕尺寸而無需滾動,則必須動態設置網格視圖行的高度。

動態設置視圖的高度也有些困難。 因為當您膨脹布局時,視圖的高度是在螺紋中測量的。 這是我用於此操作的示例。

final LinearLayout wrapper = (LinearLayout)mainLayout.findViewById(R.id.ll_categories);
        wrapper.post(new Runnable() {
            @Override
            public void run() {
                // hide view here so that its height has been already computed
                Constants.rowHeight2 = wrapper.getMeasuredHeight() / Constants.VISIBLE_ITEM_COUNT;
                initActivity();
            }
        }); 

或者,您可以覆蓋onmeasure以獲得網格視圖的最終高度。 稍后,您可以划分列表大小並找到每一行的高度。

希望我的回答對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM