【发布时间】:2015-06-02 12:37:26
【问题描述】:
我是 Android 新手。我正在做一个布局。我想在imageview下面设置textview,但我做不到。当我自己将 textview 拖到图像下方时,RelativeLayout 变为 matchparent。请看我的代码。
<?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="wrap_content"
android:background="@drawable/sample" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/imageView1"
android:text="sbxcdgdbc dhwe hdejd djhe dqe "
android:textColor="#ffffff" />
</RelativeLayout>
背景图片为500*350像素
【问题讨论】:
-
因为TextView与ImageView不在同一层级。顺便说一句,你为什么要放置所有这些 LinearLayouts?它们不仅不利于性能,还会使您的设计混乱。顺便说一句,可以通过对 TextView 使用 compound drawable 来避免 ImageView,从而进一步提高性能。
-
@DerGolem 起初我在没有太多布局的情况下让它变得简单,但我遇到了错误,这就是我使用这些的原因。
-
@DerGolem 我已经更新了我的代码。即使现在它也不起作用
-
现在,你纠正了多余的+,是的。
-
@Strider
fill_parent已弃用。改用match_parent