【问题标题】:Imageview with multiple adjacent TextViews具有多个相邻 TextView 的 Imageview
【发布时间】:2018-06-09 15:08:08
【问题描述】:

我正在尝试创建一个 android 布局,其中我有一个 imageview 以及一个两列 textview 直接位于它的右侧,所有这些都在一个滚动视图中。

像用户头像和基本信息布局一样思考。

我已经创建了一个我想要实现的线框,不幸的是我似乎无法让 imageview - textview - textview 的布局正确。

我所做的所有其他事情。

编辑 这是我没有运气的尝试:

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="none"
    android:layout_weight="1">
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:weightSum="1"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:weight="0.4"
            android:src="@drawable/profileImg" />
        <LinearLayout
            android:weight="0.6"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:weightSum="1"
            android:orientation="vertical">
            <RelativeLayout
                android:weight="0.25">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="10sp"
                    android:text="User ID"
                    android:textColor="#fff" />
                <TextView
                    android:id="@+id/pUID"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="10sp"
                    android:text="pUID"
                    android:textColor="#fff" />
            </RelativeLayout>
            <RelativeLayout
                android:weight="0.25">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="10sp"
                    android:text="Full Name"
                    android:textColor="#fff" />
                <TextView
                    android:id="@+id/fName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="10sp"
                    android:text="fName"
                    android:textColor="#fff" />
            </RelativeLayout>
            <RelativeLayout
                android:weight="0.25">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="10sp"
                    android:text="Age"
                    android:textColor="#fff" />
                <TextView
                    android:id="@+id/pAge"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="10sp"
                    android:text="pAge"
                    android:textColor="#fff" />
            </RelativeLayout>
            <RelativeLayout
                android:weight="0.25">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="10sp"
                    android:text="Date of Birth"
                    android:textColor="#fff" />
                <TextView
                    android:id="@+id/pDOB"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="10sp"
                    android:text="pDOB"
                    android:textColor="#fff" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>
</ScrollView>

【问题讨论】:

  • 显示您的 xml 代码。
  • 显示一些东西...发布您的 XML 文件或其他东西...
  • @Aspicas 我添加了一些 axml

标签: android android-layout


【解决方案1】:

尝试使用下一个XML file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <ScrollView 
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="none">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center_vertical|center_horizontal"
                android:layout_marginTop="20dp"
                android:layout_marginBottom="20dp">

                <TextView
                    android:text="TextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/textView48"
                    android:textSize="24sp"/>
            </LinearLayout>

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

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.30">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:weight="0.4"
                        android:src="@drawable/profileImg"
                        android:layout_marginLeft="10dp"/>
                </LinearLayout>

                <LinearLayout
                    android:weight="0.25"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.70">

                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1">

                        <LinearLayout
                            android:weight="0.25"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:layout_marginLeft="10dp">
                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:text="TextView"
                                android:textColor="#000"
                                android:textSize="24sp"/>
                        </LinearLayout>

                        <LinearLayout
                            android:weight="0.25"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:layout_marginLeft="10dp">
                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:textSize="24sp"
                                android:text="TextView"
                                android:textColor="#000" />
                        </LinearLayout>

                        <LinearLayout
                            android:weight="0.25"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:layout_marginLeft="10dp">
                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:textSize="24sp"
                                android:text="TextView"
                                android:textColor="#000" />
                        </LinearLayout>
                    </LinearLayout>

                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1">

                        <LinearLayout
                            android:weight="0.25"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:layout_marginLeft="10dp">
                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:text="TextView"
                                android:textColor="#000"
                                android:textSize="24sp"/>
                        </LinearLayout>

                        <LinearLayout
                            android:weight="0.25"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:layout_marginLeft="10dp">
                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:textSize="24sp"
                                android:text="TextView"
                                android:textColor="#000" />
                        </LinearLayout>

                        <LinearLayout
                            android:weight="0.25"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:layout_marginLeft="10dp">
                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:textSize="24sp"
                                android:text="TextView"
                                android:textColor="#000" />
                        </LinearLayout>
                    </LinearLayout>

                </LinearLayout>
            </LinearLayout>

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

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical|center_horizontal">

                    <TextView
                        android:text="TextView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/textView83"
                        android:layout_marginBottom="20dp"
                        android:layout_marginTop="20dp"
                        android:textSize="18sp"/>

                </LinearLayout>

            </LinearLayout>

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

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_vertical|center_horizontal">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="TextViewb"
                        android:textColor="#000"
                        android:textSize="24sp"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="TextViewc"
                        android:textColor="#000"
                        android:textSize="24sp"
                        android:layout_marginTop="20dp"/>
                </LinearLayout>

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_vertical|center_horizontal">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="TextViewd"
                        android:textColor="#000"
                        android:textSize="24sp"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="TextViewe"
                        android:textColor="#000"
                        android:textSize="24sp"
                        android:layout_marginTop="20dp"/>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

输出

【讨论】:

  • 这是一个很好的工作示例。有没有办法预先定义图像视图的大小?看起来尺寸目前是基于图像的。
  • 嗯,它应该适应所有图像...您可以通过图像高度/宽度属性的 wrap_content 或 match_parent 更改值,或者在上述 Linear_layout 上更改 layout_weight
【解决方案2】:

RelativeLayoutImageView 和 2 LinearLayoutLinearLayouts 将包含 TextViews

ImageView 将是 allignParentLeft,其他两个布局的权重为 1,布局在图像视图的左侧。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-25
    相关资源
    最近更新 更多