Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ListView中的相对布局_Android_Xml_Android Layout_Android Listview - Fatal编程技术网

Android ListView中的相对布局

Android ListView中的相对布局,android,xml,android-layout,android-listview,Android,Xml,Android Layout,Android Listview,我正在尝试从我的android应用程序中的RSS获取数据。我需要特定格式的数据。我可以做任何事情,但要让我的ListView看起来像我想要的那样。现在看起来像 我们可以看到眼睛符号和数字没有对齐。眼睛符号位于左缩略图下方。我想让它看起来像 请参阅第一个列表项,左椭圆形。眼睛视图图像和编号彼此对齐,并位于左缩略图的底部。在第二个空椭圆形的地方,我想要另一个文本视图,在那里我可以显示文本形式的新闻来源 我当前在ListView中为1 iteam编写的代码如下所示:- <!-- postit

我正在尝试从我的android应用程序中的RSS获取数据。我需要特定格式的数据。我可以做任何事情,但要让我的ListView看起来像我想要的那样。现在看起来像

我们可以看到眼睛符号和数字没有对齐。眼睛符号位于左缩略图下方。我想让它看起来像

请参阅第一个列表项,左椭圆形。眼睛视图图像和编号彼此对齐,并位于左缩略图的底部。在第二个空椭圆形的地方,我想要另一个文本视图,在那里我可以显示文本形式的新闻来源

我当前在ListView中为1 iteam编写的代码如下所示:-

<!-- postitem.xml -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="5dp"
android:background="@drawable/bg" >

<ImageView
    android:id="@+id/postThumb"
    android:layout_width="90dp"
    android:layout_height="80dp"
    android:layout_marginRight="5dp"
    android:scaleType="centerCrop"
    android:src="@drawable/logo" />

<TextView
    android:id="@+id/postTitleLabel"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@id/postThumb"
    android:layout_toRightOf="@id/postThumb"
    android:ellipsize="end"
    android:maxLines="2"
    android:text="Place for title"
    android:textIsSelectable="false"
    android:textSize="16sp" />

<TextView
    android:id="@+id/postDateLabel"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/postThumb"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@id/postThumb"
    android:maxLines="1"
    android:text="April 12, 2013"
    android:textSize="12sp" />

<TextView
    android:id="@+id/postViews"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20sp"
    android:layout_alignLeft="@+id/postDateLabel"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@+id/eye"
    android:layout_below="@id/postDateLabel"
    android:maxLines="1"
    android:text="1212"
    android:textSize="12sp" />

<ImageView
    android:id="@+id/eye"
    android:layout_width="13dp"
    android:layout_height="7dp"
    android:layout_alignLeft="@+id/postDateLabel"
    android:layout_below="@id/postDateLabel"
    android:scaleType="centerCrop"
    android:src="@drawable/eye" />

</RelativeLayout>

任何帮助都将不胜感激。如果有人能分享一个好的资源,让我可以轻松地学习这个UI设计,我将不胜感激


谢谢

问题基本上在于这一行:

android:layout_alignBottom="@id/postThumb"
在您的postDateLabel中

你说,好的,将这个标签与缩略图底部对齐,当你说你想要眼睛和postDateLabel下面的文本时,它就在那里结束了。 你要为此给我买杯啤酒:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="5dp" >

<ImageView
    android:id="@+id/postThumb"
    android:layout_width="90dp"
    android:layout_height="80dp"
    android:layout_marginRight="5dp"
    android:scaleType="centerCrop"
    android:src="@drawable/abc_ic_go" />

<TextView
    android:id="@+id/postTitleLabel"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@id/postThumb"
    android:layout_toRightOf="@id/postThumb"
    android:ellipsize="end"
    android:maxLines="2"
    android:text="Place for title"
    android:textIsSelectable="false"
    android:textSize="16sp" />

<TextView
    android:id="@+id/postDateLabel"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_above="@+id/postViews"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@id/postThumb"
    android:maxLines="1"
    android:text="April 12, 2013"
    android:textSize="12sp" />

<TextView
    android:id="@+id/postViews"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/postThumb"
    android:layout_alignLeft="@+id/postDateLabel"
    android:layout_alignParentRight="true"
    android:layout_marginLeft="20sp"
    android:layout_toRightOf="@+id/eye"
    android:maxLines="1"
    android:text="1212"
    android:textSize="12sp" />

<ImageView
    android:id="@+id/eye"
    android:layout_width="13dp"
    android:layout_height="7dp"
    android:layout_alignBottom="@id/postThumb"
    android:layout_alignLeft="@+id/postDateLabel"
    android:scaleType="centerCrop"
    android:src="@drawable/abc_spinner_ab_pressed_holo_dark" />


另外,您在xml中设置了许多不必要的属性。。我只是在几秒钟内做了这件事来帮助你。您应该阅读RelativeLayout和LinearLayout的工作原理

最佳对齐方式是使用线性布局,并将imageview和textview放在该布局中

例如:-

     <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:orientation="Horizontal" >

      <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
              />


“一个人不应该追求容易实现的目标。一个人必须培养一种本能,知道通过自己最大的努力几乎无法实现的目标。”―艾伯特·爱因斯坦这是我的座右铭,但我迫切需要这一点。我在一天中尽我所能:(帮助是唯一的一个词或这个词。)如果你把除了图像以外的所有东西都用垂直的
线性布局
包装,你可能会更容易些。我会试一试。谢谢。但是我们如何做这些决定呢?当你发现布局是如何工作的:例如线性布局,每个元素都低于前一个元素,在相对布局中,你必须ell元素与其他元素或其父元素的相对位置..等等。当您了解它们的工作方式时,您将更好地决定选择哪种布局,使事情完全符合您的要求。祝您好运:)我已编辑了我的答案,因为我复制了您提供的相同代码。这是固定的。抱歉:)“如果有帮助的话,你可以考虑批准这个答案。”请帮助我显示来源以及。回答被接受。@divyenduz,什么来源?