繁体   English   中英

相对布局中的ImageViews和TextViews

[英]ImageViews and TextViews in Relative Layouts

我想知道是否有人可以解释我遇到的一个小问题。 我正在努力让我了解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/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”将每个子项与其他子项对齐。 这似乎可以很好地与TextViews一起使用,但是我很难让ImageViews正常工作-就像它们实际上似乎没有占据任何空间一样,因为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> 

在您的文本视图上调用android:layout_below =“ @ id / idofImageView”并将图像添加到ImageView。

编辑:对不起,您想要它在右边: android:align_toRightOf="@id/ImagevIEW"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM