简体   繁体   English

如何在相对布局Android中的centerVertical中对齐imageView

[英]How to align imageView in centerVertical in Relative Layout Android

I am trying to design a row for list ... It contains 1 checkbox , 2 textView , 1 ImageView and 1 Rating Bar ... 我正在尝试为列表设计一行...它包含1个复选框,2个textView,1个ImageView和1个评级栏...

  1. After adding rating bar ImageView is not in centerVertical according to the Relative Layout 添加等级栏后,根据相对布局,ImageView不在centerVertical中
  2. I have used android:layout_marginRight="70dp" to fix it on the right position but I want to fix it using android:layout_toRightOf="@+id/list_image" 我已经使用android:layout_marginRight =“ 70dp”将其修复在正确的位置,但是我想使用android:layout_toRightOf =“ @ + id / list_image”进行修复

Here is the xml 这是XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/list_selector"
    android:orientation="horizontal"
    android:padding="5dip" >

    <!--  ListRow Left sied Thumbnail image -->
    <LinearLayout android:id="@+id/thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="3dip"
        android:layout_alignParentRight="true"
        android:background="@drawable/image_bg"
        android:layout_marginRight="5dip">

        <ImageView
            android:id="@+id/list_image"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:src="@drawable/bday"/>

    </LinearLayout>

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/thumbnail"
        android:textColor="#040404"
        android:typeface="sans"
        android:textSize="15dip"
        android:textStyle="bold"
        android:text="Ravi Ranjan" />

        <!-- GENDER -->
    <TextView
        android:id="@+id/gender"
        android:layout_marginLeft="35dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="1dp"
        android:layout_below="@id/checkBox1"
        android:textColor="#343434"
        android:textSize="12dip"
         android:text="Male" />
    <TextView
        android:id="@+id/gender"
        android:layout_marginLeft="35dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="1dp"
        android:layout_below="@id/checkBox1"
        android:layout_alignParentRight="true"
        android:layout_marginRight="70dp"
        android:textColor="#343434"
        android:rating   = "4"
        android:textSize="12dip"
         android:text="1 Aug" />

    <RatingBar
        android:id="@+id/ratingBar1"
        style = "?android:attr/ratingBarStyleSmall"
        android:layout_marginLeft="35dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_below="@id/gender"
        android:layout_marginTop="1dp"
        />

</RelativeLayout>

Try this.. 尝试这个..

Use android:layout_centerVertical="true" for thumbnail LinearLayout android:layout_centerVertical="true"用于缩略图 LinearLayout

   <LinearLayout
        android:id="@+id/thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="5dip"
        android:gravity="center"
        android:background="@drawable/image_bg"
        android:padding="3dip" >

        <ImageView
            android:id="@+id/list_image"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:src="@drawable/bday" />
    </LinearLayout>

you can try the below solid layout which will support almost all screens as per your need. 您可以尝试以下实体布局,该布局将根据需要支持几乎所有屏幕。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/list_selector"
    android:orientation="horizontal"
    android:padding="5dip" >

    <!-- ListRow Left sied Thumbnail image -->

    <LinearLayout
        android:id="@+id/thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="5dip"
        android:background="@drawable/image_bg"
        android:padding="3dip" >

        <ImageView
            android:id="@+id/list_image"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:src="@drawable/bday" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_toLeftOf="@+id/thumbnail"
        android:gravity="center"
        android:orientation="vertical" >

        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Ravi Ranjan"
            android:textColor="#040404"
            android:textSize="15dip"
            android:textStyle="bold"
            android:typeface="sans" />

        <!-- GENDER -->

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/gender"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Male"
                android:textColor="#343434"
                android:textSize="12dip" />

            <TextView
                android:id="@+id/gender"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="1dp"
                android:layout_weight="1"
                android:rating="4"
                android:text="1 Aug"
                android:textColor="#343434"
                android:textSize="12dip" />
        </TableRow>

        <RatingBar
            android:id="@+id/ratingBar1"
            style="?android:attr/ratingBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="1dp" />
    </LinearLayout>

</RelativeLayout>

Hope it will help you.. 希望对您有帮助。

暂无
暂无

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

相关问题 如何以编程方式在相对布局中对齐CenterVertical - How to align CenterVertical in Relative layout programmatically 如何在相对布局中调整TextView和ImageView的大小并将其居中对齐-Android SDK 10 - How to resize and align to center TextView to ImageView in relative layout - android sdk 10 相对布局:位于CenterVertical元素下方的layout_below - Relative layout: layout_below a CenterVertical element android:layout_alignParentTop =“ true”和android:layout_centerVertical =“ true”不会将imageView设置在屏幕顶部居中 - android:layout_alignParentTop=“true” and android:layout_centerVertical=“true” do not set the imageView centered at the the top of the screen RelativeLayout- android:layout_centerHorizo​​ntal =“true”和android:layout_centerVertical =“true”不要将imageview居中 - RelativeLayout- android:layout_centerHorizontal=“true” and android:layout_centerVertical=“true” dont center the imageview android:在相对布局中对齐 - android : align in relative layout 嵌套相对布局中的layout_centerVertical导致Android P上textviews的位置不正确 - layout_centerVertical in Nested Relative Layout causing incorrect positioning of textviews on Android P 无法根据相对布局对齐imageview - Not able to align imageview with respect to relative layout Android:将相对布局居中对齐 - Android: align relative layout to center Android 相对布局居中对齐 - Android Relative Layout Align Center
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM