繁体   English   中英

使imageButton适应不同的屏幕尺寸

[英]Fitting imageButtons into different screen sizes

我是android编程的新手。 我在将ImageButtons缩放到不同的屏幕分辨率时遇到问题。 我根据dpi制作了不同的图像尺寸,并将其分别设置为hdpi(120px * 72px,160dpi),mdpi(80px * 48px,160dpi)和xhdpi(160px * 96px,160dpi),但是在1280x720之类的屏幕分辨率上右边有一点空间。 我尝试过类似的事情:

android:scaleType="fitXY"
android:scaleType="centerInside"
android:adjustViewBounds="true"

但没有任何效果。 另外,我不太确定这些功能。 就像我说的,我是Android新手。

https://www.dropbox.com/sh/dmtcn4lxyxxh5wt/vpq9pBMOSl

<ImageButton
    android:id="@+id/imageButtonsearch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/imageButtonshare"
    android:background="@null"
    android:scaleType="centerInside"
    android:src="@drawable/selector_search"
    android:adjustViewBounds="true" />

提前致谢

您应该使用linearlayout,然后将所有imagebutton的layout_weight attr设置为0.25 Linearlayout必须位于父底部。

像这样;

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal">

    <ImageButton 
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="0.25"
        android:src="@drawable/ic_launcher"/>

    <ImageButton 
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="0.25"
        android:src="@drawable/ic_launcher"/>

    <ImageButton 
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="0.25"
        android:src="@drawable/ic_launcher"/>

    <ImageButton 
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="0.25"
        android:src="@drawable/ic_launcher"/>

</LinearLayout>

将您的layout_width属性设置为“ fill_parent”并确保scaleType为fitXY

在我们的ImageButtons中使用权重相等的属性。 与屏幕尺寸相比,它将占用空间,并使用dp not dip。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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