【问题标题】:How to place textviews center with near imageview and textview android?如何在 imageview 和 textview android 附近放置 textview 中心?
【发布时间】:2015-04-23 05:56:17
【问题描述】:

您好,我想实现类似于下面所附屏幕截图的所需输出。一个视图线分隔,我需要将 textview 放置在中心并靠近 textview 一个图像和文本的大小和颜色。如何实现?

我的代码如下:

我在顶部和底部使用了一条视图线,并使用了 textview,但它没有实现精确的输出。如何解决问题?请帮我。谢谢..

    <View
        android:id="@+id/view2"
        android:layout_width="wrap_content"
        android:layout_height="1dp"
        android:layout_below="@+id/offers_price_layout"
        android:layout_centerVertical="true"
        android:layout_marginTop="5dp"
        android:background="#cfcfcf" />
        <RelativeLayout
            android:id="@+id/size_color_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/view2"
            android:orientation="horizontal"
            >
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:weightSum="4"
                android:orientation="horizontal">
            <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1.4"
                    android:layout_height="fill_parent"
                    android:text="Size"
                android:paddingRight="10dp"
                android:gravity="center"
                    />
                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="0.3"
                    android:layout_height="fill_parent"
                    android:text="7"
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp"
                    android:layout_marginTop="2dp"
                    />

                <View
                    android:layout_width="1dp"
                    android:layout_height="fill_parent"
                    android:background="#cfcfcf"
                    />
                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1.7"
                    android:layout_height="fill_parent"
                    android:text="Color"
                    android:gravity="center"
                    />
                <ImageView
                    android:layout_width="0dp"
                    android:layout_weight="0.6"
                    android:layout_height="fill_parent"

                    android:paddingTop="10dp"
                    android:paddingBottom="10dp"
                    android:src="@drawable/product_wish"
                    />
            </LinearLayout>
            </RelativeLayout>

    <View
        android:id="@+id/view3"
        android:layout_width="wrap_content"
        android:layout_height="1dp"
        android:layout_below="@+id/size_color_layout"
        android:layout_centerVertical="true"
        android:background="#cfcfcf" />

下面是我想要实现的截图。

【问题讨论】:

  • 我可以知道投反对票的原因吗?

标签: android android-layout android-relativelayout android-layout-weight


【解决方案1】:

按照以下步骤操作:

  1. 创建父水平线性布局
  2. 放置 2 个权重相等的相对布局
  3. 在两者中插入水平线性布局,并在父级中居中
  4. 放置一个 TextView 和一个 ImageVew 来包装内容

【讨论】:

    【解决方案2】:

    你要居中对齐哪个textview,是和text 7对齐的吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      • 2019-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      相关资源
      最近更新 更多