[英]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.