【问题标题】:Android ImageButton for various screen sizes适用于各种屏幕尺寸的 Android ImageButton
【发布时间】:2015-02-01 11:58:08
【问题描述】:

我正在尝试创建一个适合各种屏幕的图像按钮。但是,我无法让图像按钮正确适应更大的屏幕,而是在图像按钮上显示小得多的图像。

到目前为止我所尝试的:

  • 我已经使用这个link 生成了九个补丁图像,但是即使我将文件添加到drawable:ldpi、mdpi、ldpi、xhdpi 和xxhdpi 文件夹,图像仍然比屏幕宽度短李>
  • 我尝试过使用android:scaleType="fitXY"android:adjustViewBounds="true"。这确实会根据每个屏幕尺寸进行调整,但您可以看到图像外围的灰色图像按钮可点击区域的边缘。

下面的布局文件有什么问题吗?或者是否需要某些图像尺寸?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ScrollView
    android:id="@+id/homepageScrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" >

    <RelativeLayout
        android:id="@+id/homepageRelLayout2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="fill" >

    <ImageButton
        android:id="@+id/homepageImageButton"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="40dp"
        android:src="@drawable/someImage" />

    </RelativeLayout>

</ScrollView>

</RelativeLayout>

【问题讨论】:

    标签: android imageview imagebutton


    【解决方案1】:

    如果你使用 ImageView + 点击监听,你将失去按钮输入/输出效果。 也许你可以试着给你的 ImageButton 一个透明的背景,像这样:

    android:background="?android:selectableItemBackground"
    

    不要使用@null@android:color/transparent,它们也会失去按钮效果。

    顺便说一句,android:selectableItemBackground 不适用于像 2.x 这样的旧 android 版本

    【讨论】:

      猜你喜欢
      • 2016-07-02
      • 1970-01-01
      • 2018-10-14
      • 2022-01-24
      • 2016-07-02
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 2015-12-06
      相关资源
      最近更新 更多