Android 相对布局中的图像视图和文本视图

Android 相对布局中的图像视图和文本视图,android,android-layout,Android,Android Layout,我想知道是否有人能解释我遇到的一个小问题。我正试着让我的头脑围绕着亲戚们,并有以下几点: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:orientation="vertical" android:background="#ffffff" android:layout_h

我想知道是否有人能解释我遇到的一个小问题。我正试着让我的头脑围绕着亲戚们,并有以下几点:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:background="#ffffff"
    android:layout_height="fill_parent" >        

            <ImageView
                android:id="@+id/newsImage"
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:layout_alignParentLeft="true"
                android:background="#ffffff"  >
            </ImageView>            

            <TextView
                android:id="@+id/newsSubtitle"
                android:layout_height="fill_parent"
                android:layout_width="200dp"
                android:textColor="#0098bf"
                android:layout_centerVertical="true"
                android:layout_alignRight="@+id/newsImage"
                android:textSize="18sp">
            </TextView>  

            <TextView
                android:id="@+id/newsId"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:visibility="invisible"
                android:textSize="0sp"  >
            </TextView>     
</RelativeLayout> 

据我所知,在RelativeLayouts中,您可以使用“alignParentLeft=“true”将子项与父项(RelativeLayout)对齐,也可以使用alignRight=“@+id/childId”将每个子项与其他子项对齐。这对于TextView来说似乎已经足够好了,但是我在让ImageView正常工作时遇到了问题——它们似乎实际上没有占用任何空间,因为TextView只是位于图像的顶部,而不是与图像的右侧对齐

我是否误解了这里的某些内容,或者RelativeLayouts是否有不同的对齐图像/文本组合的方法?

使用此代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:background="#ffffff"
    android:layout_height="fill_parent" >        

            <ImageView
                android:id="@+id/newsImage"
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:layout_alignParentLeft="true"
                android:background="#ffffff"  >
            </ImageView>  

            <TextView
                android:id="@+id/newsId"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:visibility="gone"
                android:textSize="0sp"  >
            </TextView>

            <TextView
                android:id="@+id/newsSubtitle"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:textColor="#0098bf"
                android:textSize="18sp" />

</RelativeLayout> 

在textview上调用android:layout_down=“@id/idofImageView”,并将图像添加到ImageView中


编辑:很抱歉,您希望它位于右侧:
android:align\u toRightOf=“@id/ImagevIEW”

我尝试了layout\u height=“wrap\u content”和layout\u height=“match\u parent”,它们都给出了相同的结果-textview位于ImagevIEW顶部:/试着使用一些dp,比如android:layout\u height=“100dp”或者使用wrap content
android:layout\u height=“wrap\u content”
好的,那么你到底想要什么样的内容呢。您想在图像视图的正下方或正上方显示文本视图。我已更新了答案,请查看。这正是您正在寻找的,或者您仍然需要一些更改…感谢您的帮助,事实证明我引用的ImageView是错误的,并调用alignRight而不是toRightOf。再次感谢你的帮助!我已经在文本视图“android:layout_alignRight=“@+id/newsImage”中这样做了,我还尝试删除+符号,但也没有成功。+符号表示您在调用现有id时正在创建一个新id。以后在引用其他视图时不要使用加号。如果图像很大,textview将与之重叠,但代码可能仍然有效。使用ic_启动器(应用程序图标)作为要测试的imageview的源来尝试。