簡體   English   中英

相對布局中的中心GridView

[英]Center GridView in Relative layout

我有簡單的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<GridView
    android:id="@+id/photo_browser_grid_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:gravity="center"
    android:horizontalSpacing="5dp"
    android:verticalSpacing="5dp"
    android:stretchMode="none"
    android:numColumns="auto_fit" 
    android:columnWidth="100dp">
</GridView>

我想將GridView放在Relative布局中。 我的間距總是固定的。 結果我將GridView對齊到左邊。 如何將其置於父母的中心?

網格視圖

對於布局中的GridView, android:numColumns="auto_fit"android:layout_width="wrap_content"沖突。 這意味着:要計算要形成的列數,需要寬度,但要找到寬度,我們需要包含多少列,循環依賴。

您可以使用android:stretchMode讓列填滿空白區域。

暫無
暫無

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

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