【发布时间】:2015-09-30 12:02:29
【问题描述】:
我在 android 工作时总是遇到这个问题,那就是在按钮中设置图像。我有一个我想在按钮中设置的图像,所以我有这个按钮图像的多种分辨率,用于不同的存储桶,以支持多种屏幕尺寸。
现在,当我想在按钮中设置它时,我得到了轻微的图像螺丝。看起来宽度上的图像比高度上的图像大,但实际上并非如此。让我在按钮中设置图像后与您分享图片。这个屏幕短是 android 三星 Galaxy s4 设备,它是 xxhd 设备
现在你可以很容易地看到它看起来有多糟糕。
这就是我在 xml 中设置它的方式
<Button
android:id="@+id/btn_flip_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/flip_image"
/>
但是当我在 Imageview 中设置此图像时,一切看起来都如预期的那样好。所以问题不在于图像也不在于 xml,而是使用 Button 的方式。那么任何人都可以告诉我在 button 或 Imagebutton 中使用图像的最佳方式是什么。
请告诉我为什么在我尝试在按钮中设置图像时总是发生这种情况,而最终当我使用图像视图时,我总是得到我想要的结果。
(如何使用 Imageview 让我失去了 按钮自然且默认具有。)
**Edit1 ** 这是我使用按钮的 xml 部分
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|top"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:background="@drawable/menu_bg"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:gravity="center"
>
<Button
android:id="@+id/btn_flip_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/flip_image"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="5dp"
/>
<Button
android:id="@+id/btn_flip_suit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/flip_suit" />
<TextView
android:layout_width="match_parent"
android:layout_height="5dp"
/>
<Button
android:id="@+id/btn_change_suit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/change_suit" />
<TextView
android:layout_width="match_parent"
android:layout_height="5dp"
/>
<Button
android:id="@+id/btn_share"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:background="@drawable/share_btn" />
<TextView
android:layout_width="match_parent"
android:layout_height="5dp"
/>
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/save_image"
/>
</LinearLayout>
所以任何人都请让我明白我做错了什么或者使用自定义图像的最佳方式是什么。 ??
【问题讨论】:
-
你可以使用ImageButton
-
我在我的问题中提到我想使用 Button ,而使用 imageButton 也需要图像的透明部分,看起来并不酷
-
“也将图像的透明部分放在里面”,你能澄清一下吗?
-
我的意思是图像有角,并且默认情况下按钮似乎有填充,这是我的想法,有些东西不能让图像看起来像它应该的那样,我可以猜到最好的是,默认情况下我认为按钮是矩形的,所以必须有一些东西总是试图让按钮在纵横比上保持一致
标签: android android-layout android-button