android - 在 TableLayout 中右对齐

标签 android android-layout alignment tablelayout

我仍然没有找到如何在 XML 中做到这一点的解决方案 我希望我的 textview 向左对齐,而我的 imageview 向右对齐,代码如下:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<TableRow
    android:id="@+id/tr1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:layout_height="wrap_content"
        android:text="Vibration"
        android:layout_width="wrap_content" />


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dip"
        android:src="@drawable/ic_launcher" />


</TableRow>
</TableLayout>

有什么办法吗?

最佳答案

尝试将您的 TableRow 更改为以下内容:

<TableRow
    android:id="@+id/tr1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
    <TextView
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:text="Vibration"
        android:gravity="left" />
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dip"
        android:gravity="right"
        android:src="@drawable/ic_launcher" />
</TableRow>

关于android - 在 TableLayout 中右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12185670/

相关文章:

android - 将项目迁移到 Android Studio 时显示的旧式 Android 菜单

html - CSS - 将 Font Awesome 图标与一段文本对齐

android - 以编程方式使用 SSH Android

Android NDK GCC 似乎是 clang - 它应该是这样吗?

java - 使用 Android 硬件侧边按钮

android - 创建自定义工具栏?

android - 在android中创建自定义LockScreen

当ListView中没有项目时Android addHeaderView消失

ios - UITextView 对齐,插入符向左

winforms - 如何右对齐菜单中的快捷键?