Android-像表格行一样对齐文本视图
我有一个用数据填充的列表视图,我试图让我的布局看起来像这样: 在使用线性布局或相对布局时,有没有办法创建这种布局?我试过使用TableRows,虽然它可以工作,但它在将左侧和右侧分开的列之间留下了一个间隙,看起来一点也不吸引人Android-像表格行一样对齐文本视图,android,android-layout,Android,Android Layout,我有一个用数据填充的列表视图,我试图让我的布局看起来像这样: 在使用线性布局或相对布局时,有没有办法创建这种布局?我试过使用TableRows,虽然它可以工作,但它在将左侧和右侧分开的列之间留下了一个间隙,看起来一点也不吸引人 不太确定从哪里开始……非常感谢您的帮助。您可以通过在单亲线性布局中放置一个2线性布局来实现这一点。其中父android:orientation应该是水平的。对于每一行,您都需要使用此技术 我确实在我的项目中使用了这种方法 我正在为一行编写一个示例。请参考 <Lin
不太确定从哪里开始……非常感谢您的帮助。您可以通过在单亲线性布局中放置一个2线性布局来实现这一点。其中父
android:orientation
应该是水平的。对于每一行,您都需要使用此技术
我确实在我的项目中使用了这种方法 我正在为一行编写一个示例。请参考
<LinearLayout
android:id="@+id/line1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="Issue Number"
android:layout_weight="1.0"
android:layout_height="wrap_content"
android:layout_width="0px"
android:gravity="right"/>
<TextView
android:text="6046"
android:layout_weight="1.0"
android:layout_height="wrap_content"
android:layout_width="0px"
android:gravity="left"/>
</LinearLayout>
您需要为所有行编写此文件,然后将其包含在父LinearLayout下,并具有垂直方向。您可以提供一个xml来格式化ListView中的每一行,其中每一行是一个简单的水平LinearLayout,具有两个文本视图 因此,一些与此相同的东西: 关于ListView的更详细文章:
我用前两行创建了一个布局:
<?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" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Issue Number:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date Received:"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_toRightOf="@+id/linearLayout1"
android:gravity="left"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6,046"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="09/02/2008"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</RelativeLayout>
这不是一个好答案,因为它没有考虑第二列textview可能有多行的位置。这个答案可能是最好的,我要添加的唯一一点是,您可以指定左侧textview的权重为1.0,右侧textview的权重为3.0。这将达到上述预期结果。