简体   繁体   English

使imageButton适应不同的屏幕尺寸

[英]Fitting imageButtons into different screen sizes

i am new to android programming. 我是android编程的新手。 I have a problem scaling ImageButtons to different screen-resolutions. 我在将ImageButtons缩放到不同的屏幕分辨率时遇到问题。 I made different image sizes based on the dpi and put them into hdpi(120px*72px,160dpi), mdpi(80px*48px,160dpi) and xhdpi(160px*96px,160dpi) But on screen-resolutions like 1280x720 there is a little bit of space on the right side. 我根据dpi制作了不同的图像尺寸,并将其分别设置为hdpi(120px * 72px,160dpi),mdpi(80px * 48px,160dpi)和xhdpi(160px * 96px,160dpi),但是在1280x720之类的屏幕分辨率上右边有一点空间。 I tried things like: 我尝试过类似的事情:

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

but nothing worked. 但没有任何效果。 Also, i am not quite sure what these do. 另外,我不太确定这些功能。 Like i said, i am new to android. 就像我说的,我是Android新手。

https://www.dropbox.com/sh/dmtcn4lxyxxh5wt/vpq9pBMOSl 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" />

Thanks in advance 提前致谢

You should use linearlayout and than set all imagebutton's layout_weight attr to 0.25 Linearlayout must be in the parent bottom. 您应该使用linearlayout,然后将所有imagebutton的layout_weight attr设置为0.25 Linearlayout必须位于父底部。

Like this; 像这样;

<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

Use equal weight attribute in our ImageButtons. 在我们的ImageButtons中使用权重相等的属性。 It will occupy the space as compare to Screen Sizes, and use dp not dip. 与屏幕尺寸相比,它将占用空间,并使用dp not dip。

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

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