2010-06-15 105 views
0

他是我的TextView的一个例子,它离开了屏幕的右侧。我尝试设置填充和东西,但似乎没有任何工作。有任何想法吗?这是我的层次结构, 滚动型,TableLayoutAndroid:内容关闭屏幕

<TableRow> 
    <TextView 
    android:layout_column="1" 
     android:id="@+id/text_price" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:inputType="textCapCharacters" 
     android:padding="2dip" 
     android:text="@string/game_price" 
    /> 
    <EditText 
     android:id="@+id/gameprice" 
     android:inputType="textCapCharacters" 
     android:gravity="right" 
     android:minWidth="120dip" 
    /> 
    </TableRow> 

回答

4

尝试设定的TextView的宽度为wrap_content,取出layout_column = 1(不是必需的,AFAIK),并设置的EditText为wrap_content的高度和宽度。

无论如何,填充屏幕的textview和其右侧的edittext至少有120dip的宽度是很奇怪的。如果你坚持使用TableLayout,也许你必须使用元素的权重,我不太确定这是如何在tableLayout中工作的。要填充屏幕的宽度,请在TableLayout中用fill_parent定义该宽度。

如果你想要的是一个TextView采取由EditText上所剩下的全部空间摆放正确,一个RelativeLayout的会做的工作

<RelativeLayout> 
     <EditText 
      android:id="@+id/gameprice" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="textCapCharacters" 
      android:gravity="right" 
      android:minWidth="120dip"/> 
     <TextView 
      android:id="@+id/text_price" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:inputType="textCapCharacters" 
      android:padding="2dip" 
      android:text="@string/game_price" 

      android:layout_toLeftOf="@id/gameprice"/> 
    </RelativeLayout> 

你需要用的EditText的位置打,该TextView将坚持其左侧。

+0

RelativeLayout为我工作。我有三栏,中间有一栏文字将页面右侧的文字推开。我使用了RelativeLayout,它的左列layout_alignParentLeft ='true',右列layout_alignParentRight ='true',中间列声明为third列,layout_toRightOf列为左列,layout_toLeftOf列右列。 – Gravitoid 2013-10-23 14:01:05