[英]Scrollable Perfectly Symmetrical ImageButtons in XML Android
在我的Android應用中,我想創建一個具有相同寬度/高度的可滾動圖像網格。 我不想使用GridView,因為不會有太多圖像。 到目前為止,我有:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:background="@null"
android:src="@drawable/food"/>
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:background="@null"
android:src="@drawable/music" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:background="@null"
android:src="@drawable/offcampus"/>
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitCenter"
android:background="@null"
android:src="@drawable/sports" />
</LinearLayout>
</LinearLayout>
</ScrollView>
它非常接近我想要實現的目標,但是第二個LinearLayout(layout_height為0dp的那個)使前兩個ImageButton占據了屏幕的大部分,因此用戶必須滾動很多才能看到接下來的兩個ImageButton。 換句話說,圖像“行”之間的空間太大。 有什么辦法可以解決這個問題?
我附上一張照片,以防萬一。
謝謝你的幫助。
檢查多余的空間是否是由於LinearLayout
太高或ImageButton
本身造成的。 您可以在Eclipse的“ 設備”視圖的ADT中使用“轉儲視圖層次結構”按鈕。
我懷疑這是使用圖像原始高度的ImageButton
。 查看是否在ImageButton
的幫助下設置android:adjustViewBounds
來解決該問題。 請參閱參考資料: http : //developer.android.com/reference/android/widget/ImageView.html#attr_android : adjustViewBounds
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.