无法在LinearLayout和Weight属性集中调整图像大小

时间:2015-11-27 15:48:57

标签: java android android-layout android-activity android-studio

我尝试调整图片大小并增加图标大小,但我已将它们添加到LinearLayout中,每个5个图标共享重量。它们适合自己,因此我无法增加它们的图标大小/高度/宽度。

快照:

enter image description here

这是我的XML:

<LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ffffff"
            android:orientation="horizontal"
            android:weightSum="5">

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="60dp"
                android:layout_weight="1"
                android:background="@null"
                android:src="@drawable/feed_blue" />

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="60dp"
                android:layout_weight="1"
                android:background="@null"
                android:src="@drawable/compass" />

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="60dp"
                android:layout_weight="1"
                android:background="@null"
                android:src="@drawable/circle_blue" />

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="60dp"
                android:layout_weight="1"
                android:background="@null"
                android:src="@drawable/heart_beat" />

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="60dp"
                android:layout_weight="1"
                android:background="@null"
                android:src="@drawable/user_icon_female" />

        </LinearLayout>

我需要按照自己的意愿增加/减少我的图标大小,但Weight属性可能会限制该功能。我怎样才能完成那些人呢?

2 个答案:

答案 0 :(得分:0)

对于普通应用,您需要所有Android资源的图像包,例如 mipmap-hdpi,mipmap-mdpi,mipmap-nodpi,mipmap-xhdpi,mipmap-xxhdpi,mipmap-xxxhdpi ,您不应该更改图像大小,如果您没有图像包尝试在所有按钮中播放android:scaleType,例如android:scaleType="centerCrop"

答案 1 :(得分:0)

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffffff"
            android:orientation="horizontal"
            android:weightSum="5">

            <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@null"
                android:src="@drawable/feed_blue" />

            <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@null"
                android:src="@drawable/compass" />

            <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@null"
                android:src="@drawable/circle_blue" />

            <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@null"
                android:src="@drawable/heart_beat" />

            <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@null"
                android:src="@drawable/user_icon_female" />

        </LinearLayout>

在这种情况下,它们都占总宽度的20%,您可以通过改变重量轻松改变宽度。此外,您还可以使用填充属性更改宽度和高度。