java - 将布局放置在列表项内

标签 java android android-layout

我有一个列表,我想在列表项的左侧显示图像,在图像的右侧显示图像 一系列垂直对齐的小部件,其中一个是 include:@layout
有了相对布局,我可以使用图片右侧的布局添加小部件,但是: 1)我无法将线性布局对齐到图片右侧,因为似乎没有这样的属性 2)如果没有将小部件嵌套在线性布局中并将它们仅放置在选择的右侧和另一个的顶部,我无法将 include:@layout 放置在我想要的位置,因为它没有 layout_bellow 等属性。
我怎样才能创建这样的布局?

更新:

++++++++ ++++++++++++++++++++
+IMAGE +  TEXTVIEW          +
+         +   LAYOUT FILE   +
+         +         TEXTVIEW+
+++++++++++++++++++ TEXTVIEW+  

更新:

<?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="match_parent">


    <ImageView
        android:id="@+id/thumb"
        android:layout_alignParentLeft="true"
        />

    <TextView
        android:id="@+id/friend_name”
        android:layout_toRightOf="@id/thumb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="fill_horizontal"
        android:gravity="top"
       />


    <ViewStub
        android:id="@+id/stub_friend_status”
        android:inflatedId="@+id/friend_status”
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/thumb"
        android:layout_below="@id/friend_name"
        android:layout="@layout/friend_status”/>

    <TextView
        android:id="@+id/latest_date”
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/stub_friend_status"
        android:layout_toRightOf="@id/thumb"
       />


    <ViewStub
        android:id="@+id/stub_general_info”
        android:inflatedId="@+id/general”
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/latest_date"
        android:layout_alignParentBottom="true"
        android:layout="@layout/general_info”/>

</RelativeLayout>

最佳答案

这里是布局,左右部分可以均等,左边放图片,右边可以垂直布局:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >

    //left part
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        >

        <FrameLayout
            android:id="@+id/image_frame"
            android:layout_width="img_width"
            android:layout_height="img_height"
            android:gravity="center"
            >

        <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/your_img"/>

        </FrameLayout>

    </LinearLayout>

    //right part
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1"
        android:gravity="center_vertical"
        >


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/view_1"
               ... ...
            android:layout_gravity="left"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/view_2"
            ... ...
            android:layout_gravity="left"
            />

            ... ...            

    </LinearLayout>

</LinearLayout>

如果你想让左边比右边小,那么你可以将左/右的layout_weight更改为1/2或2/3...

希望这有帮助!

关于java - 将布局放置在列表项内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28987067/

相关文章:

java - 确定哪个 CSS 框架与 Selenium 一起使用

java - 在 Eclipse 中导入 SlidingMenu?

android - 使用 PhoneGap 将 Facebook、Twitter、Google+ 集成到 Android 应用程序中

java - 使用 PopupWindow 的 showAtLocation(View, int, int, int) 时遇到问题

Android - 更小的 ActionBar 选项卡

java - 使用java在Linux中运行的程序列表

本地容器上的java spring boot应用程序无法访问aws

java - 如何按最新日期对列表进行排序?

android - 如何在数据库中更新其内容字符串时更新 ListView 行?

android - 资源和布局方向仅在 Android 8.0 及更高版本上呈现不正确