图标和文本在自定义行布局中正确对齐?

时间:2015-11-13 10:28:10

标签: android xml android-layout android-relativelayout

如何使图标和文字水平显示以具有相同的高度和设计?我的意思是,如果您看到Twitter,他们将会Retweetsfavorites并且它的数量都会正确对齐,高度和宽度相同。

同样,我应该如何实现?

这是我目前的布局:

<?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" android:padding="15dp"
    android:id="@+id/relative">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="This is some text which used to test. Don&apos;t care this. This will be updated dynamically"
        android:id="@+id/content"
        android:layout_marginLeft="5dp"
        android:layout_alignParentTop="true" />


       <ImageView
           android:layout_width="17dp"
           android:layout_height="17dp"
           android:src="@drawable/favorite"
           android:id="@+id/imageView"
           android:padding="1dp"
           android:layout_marginTop="15dp"
           android:layout_below="@+id/content"
           android:layout_alignParentLeft="true"
           android:layout_alignParentStart="true" />


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="33"
        android:id="@+id/favcount"
        android:textSize="13dp"
        android:textColor="@color/md_orange_700"
        android:layout_marginLeft="5dp"
        android:layout_marginStart="5dp"
        android:layout_below="@+id/content"
        android:layout_marginTop="15dp"
        android:layout_toRightOf="@+id/imageView"
        android:layout_toEndOf="@+id/imageView" />


        <com.github.curioustechizen.ago.RelativeTimeTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="3 hrs ago"
            android:textSize="13dp"
        android:id="@+id/postedDate"
            android:layout_below="@+id/content"
            android:layout_marginTop="17dp"

            android:layout_alignRight="@+id/content"
            android:layout_alignEnd="@+id/content" />


        <ImageView
        android:layout_width="17dp"
        android:layout_height="17dp"
        android:src="@drawable/ic_time"
        android:id="@+id/imageView2"
            android:layout_marginRight="5dp"
            android:layout_marginEnd="5dp"
            android:layout_below="@+id/content"
            android:layout_marginTop="16dp"
            android:layout_toLeftOf="@+id/postedDate"
            android:layout_toStartOf="@+id/postedDate" />


</RelativeLayout>

目前的设计有高度和宽度不合适的问题(数量和图标不同)

enter image description here

我的图标应该有多大? 您可以看到心脏并且其计数未正确对齐。

1 个答案:

答案 0 :(得分:0)

将图标和计数布局包裹在水平线性布局中。使用以下内容将两个内部布局设置为在此布局中居中:

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"