android - 左对齐文本,右对齐复选框

标签 android android-layout

我正在尝试为 ListView 创建一个布局,右侧有一个复选框,左侧有一些文本。复选框应一直对齐到右侧,TextView 应一直对齐到行的左侧,例如:

 ------------------------
 text            checkbox
 ------------------------
 text            checkbox
 ------------------------
 text            checkbox
 ------------------------

这是我目前所拥有的:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:paddingLeft="5dip"
      android:paddingRight="5dip"
      android:paddingTop="8dip"
     android:paddingBottom="8dip"
>

<TextView  
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left" 
/>

<CheckBox 
    android:id="@+id/chekcbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="right" 
 /> 

 </RelativeLayout>

但是,实际呈现的是 TextBox 将复选框覆盖在行的左侧。

最佳答案

并在复选框属性中将复选框的框移到右侧

android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"

关于android - 左对齐文本,右对齐复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7989014/

相关文章:

android - 非抽象且不重写抽象方法

android - Meteor Cordova 热代码插入应用程序大小限制? (和其他差距)

android - ConsumerProguardFiles 与 ProguardFiles

android - 在启动时,我的 Activity 屏幕位置切断了一半的 UI

android - CollapsingToolbarLayout 中 ImageView 的 OnClickListener

java - 在 TextView 中的两个可绘制对象之间绘制线条

android - 将返回按钮添加到操作栏

Android 自定义键盘无法调整窗口大小问题

java - Android Studio 2.3.2 由于错误错误:Execution failed for task ':app:dataBindingProcessLayoutsDebug' 而无法构建项目

Android Glide 直接从字符串中加载 SVG 图片