简体   繁体   English

ListView Android中的相对布局

[英]Relative layout in ListView android

I am trying to fetch data from RSS in my android app. 我正在尝试从Android应用程序中的RSS提取数据。 I need the data in a specific format. 我需要特定格式的数据。 I am able to do everything but get my ListView to look as I want. 除了我想要的ListView之外,我能够做所有事情。 It currently looks like 目前看起来像

在此处输入图片说明

We can see that the eye symbol and the number are not aligned. 我们可以看到眼睛符号和数字未对齐。 And that the eye symbol is below the left thumbnail. 眼睛符号在左缩略图下方。 I want it to look like 我希望它看起来像

在此处输入图片说明

Refer to the 1st list item, left oval. 请参阅第一个列表项,左椭圆形。 The eye view image and number are aligned with each other and to the bottom of left thumbnail. 眼图和编号彼此对齐,并位于左缩略图的底部。 And at the place of 2nd empty oval I want another TextView where I would show the source of news as text. 在第二个椭圆形的地方,我想要另一个TextView,它将新闻源显示为文本。

My current code for 1 iteam in ListView goes like this :- 我当前在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>

Any help would be greatly appreciated. 任何帮助将不胜感激。 I would be thankful if someone could share a good resource where I could learn this UI designing easily. 如果有人可以共享一个很好的资源,让我可以轻松地学习UI设计,我将非常感激。

Thanks 谢谢

The problem is basicaly this line: 问题基本上是这一行:

android:layout_alignBottom="@id/postThumb"

in your postDateLabel. 在您的postDateLabel中。

You said, okay, align this label to the thumbnail bottom, and when you say that you want the eye and the text below the postDateLabel, that's where it ends up. 您说,好的,将此标签与缩略图底部对齐,当您说想要眼睛和postDateLabel下面的文本时,它就是结尾。 You're gonna buy me a beer for this: 你要为此给我买啤酒:

<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" />

PS You have a lot of unnecessary atributes set in xml.. I just did this in a few sec to help you. PS:您在xml中设置了许多不必要的属性。.我只是在几秒钟内完成了此操作,以帮助您。 You should read how RelativeLayout and LinearLayout work. 您应该阅读RelativeLayout和LinearLayout的工作方式。

The best way to align is to use Linear layout and put imageview and textview within that layout 对齐的最佳方法是使用线性布局,然后将imageview和textview放在该布局中

For example :- 例如 :-

     <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"
              />

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

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