简体   繁体   English

如何居中对齐相对布局中同一行中的多个项目

[英]How to center align multiple items in same row within relative layout

Is it possible to center align these two items horizontally together without using 1 table row? 是否可以在不使用1个表格行的情况下将这两个项目水平居中对齐? These items are within a relative layout. 这些项目在相对布局内。

    <ImageView
        android:id="@+id/image_warning"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/stat_sys_warning"
        android:padding="5dp" />
    <TextView
        android:id="@+id/textView_msg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="message"
        android:layout_toEndOf="@id/image_warning" />

如果将两个项目放置在linearLayout中,然后将重心设置为水平,该怎么办?

You can use "drawableLeft" and remove the imageView. 您可以使用“ drawableLeft”并删除imageView。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:background="@android:color/holo_orange_light"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView_msg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:drawableLeft="@android:drawable/stat_sys_warning"
        android:gravity="center"
        android:text="message" />
</RelativeLayout>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM