2016-03-03 125 views
0

我在写一个Xamarin应用程序,其中有3列和多行的表格。如何创建3列布局并保持中间列居中

some text | + | some text 
a different | + | blah blah blah 
     text | + | more and more 

第1列和第3列将包含改变长度的各种文本字符串。第1列应该右对齐,第3列应该是左对齐的。中间一列是一个Drawable,其中包含一个应与下一行对齐的图形,因此应始终居中(上面的示例显示所有+排列)。

我正在使用BaseAdapter <>,自定义视图包含带有TextView/ImageView/TextView作为3列的LinearLayout。

我已经尝试过重力,layout_gravity & layout_weight的各种组合,但中间的列总是似乎移动。

关于如何保持中间列居中的任何建议?

回答

1

试试你的单元布局。调整重量(确保它们始终合计为100)来调整列宽。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="30" 
     android:text="Left text"/> 


    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="40"> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:drawable="@drawable/your_drawable"/> 
    </FrameLayout> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="30" 
     android:text="Right text"/> 

</LinearLayout> 
+0

中间一列现在排队。谢谢。 – Neil