繁体   English   中英

XML Android中可滚动的完全对称的ImageButton

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM