昨天我试了一整天也没能解决它。我已经搜索了答案,但没有找到任何类似我的问题的东西。可能很容易解决,但我不理解。
我有以下简单的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
... ... >
<LinearLayout
... ... >
<Button
android:id="@+id/registrarUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dip"
android:gravity="center"
android:padding="15dp"
android:background="@drawable/button_shape"
android:text="@string/registrar"
android:textColor="@color/tinto" />
</LinearLayout>
</RelativeLayout>
无法在按钮上显示文本!!
这是我的 strings.xml
文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Android GCM</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="btn_aceptar">Aceptar</string>
<string name="reg_gcm">Reg GCM</string>
<string name="btn_desreg_gcm">DesReg GCM</string>
<string name="nombre_usuario">Usuario</string>
<string name="registrar">Registrar</string>
</resources>
这是我的button_shape.xml
文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#80000000"
android:endColor="#80f2f2f2"
android:angle="-90"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="13dp" />
</shape>
即使删除了
android:background="@drawable/button_shape"
(我认为它可能是问题所在),它仍然不起作用。
在控制台中,我可以看到按钮上显示的正确文本...但是当我在设备上运行项目时却没有...:(
我做错了什么?我相当新手,找不到错误。
有人遇到过同样的问题吗?请给出建议,谢谢!
编辑:
问题解决了!!!
我刚才意识到"LinerarLayout"设置了固定的"height"!这切断了按钮!
因此,我将"android:layout_height="200DP"
更改为"android:layout_height="wrap_content"
就可以了。
希望这能帮助其他人不要浪费太多时间在像这样的“小事”上。
谢谢和问候!