gpt4 book ai didi

android - 为什么 Android 坚持要压扁我的 Button?

转载 作者:行者123 更新时间:2023-11-30 02:50:12 31 4
gpt4 key购买 nike

我有一个漂亮的 facebook 按钮图片:

My Regular Facebook Login Button

但我的 Android 布局一直在挤压它:

enter image description here

谁能帮忙看看我的布局文件:

<?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" >

<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/tagline"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:contentDescription="@string/app_description"
android:src="@drawable/logo" />

<TextView
android:id="@id/tagline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/tagline"
android:textSize="22sp" />

<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tagline"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:background="@drawable/login_button_normal"
android:text="@string/login"
android:textStyle="bold" />

</RelativeLayout>

最佳答案

您正在使用一个包含文本的Button。属性 android:layout_width="wrap_content" 适用于文本的宽度,而不适用于可绘制背景的宽度。

您可以:

  • 将文本整合到您的 .png 文件中。

  • 使用 9 补丁

  • 创建一个可绘制对象以定义蓝色圆角矩形,并创建一个只有白色“f”和垂直线的图像。然后你可以使用一个内部有 drawable 的 TextView:

     <TextView
    ...
    android:text="Log in"
    android:drawableLeft="{Your image (white f)}"
    android:background="{Your drawable (blue background)}"
    ... />

关于android - 为什么 Android 坚持要压扁我的 Button?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24331972/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com