spa*_*key 5 android android-layout android-relativelayout
当我开始在 Android 上工作时,这种情况经常发生。按钮元素内的文本未完全显示。有什么问题吗?我尝试了文本方向、对齐方式、重力,但没有任何效果。

其背后的代码:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="@string/latestButtonString"
android:background="@drawable/roundbutton" />
Run Code Online (Sandbox Code Playgroud)
请帮助并非常感谢。
更新:这是 roundbutton.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<!-- you can use any color you want I used here gray color-->
<solid android:color="#ABABAB"/>
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
小智 7
我遇到了这个问题,我通过将按钮的 xml 从使用工具:更改为 android: 作为文本属性来解决它。下面的示例(最后一行是更改的行):
<Button
android:id="@+id/btn_settings"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#F6F6F6"
tools:text="App Settings" />
Run Code Online (Sandbox Code Playgroud)
变成...
<Button
android:id="@+id/btn_settings"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#F6F6F6"
android:text="App Settings" />
Run Code Online (Sandbox Code Playgroud)
您能否通过android:background="@drawable/roundbutton"从按钮属性中删除来进行检查。如果文本完全显示,那么您可能需要修改@drawable/roundbutton"您设置的内容fixed width,因此按钮中的文本不完全可见。
| 归档时间: |
|
| 查看次数: |
14561 次 |
| 最近记录: |