Android:内容离开屏幕

Jam*_*mes 0 android

他是我的 TextView 的一个例子,它离开了屏幕的右侧。我尝试设置填充和东西,但似乎没有任何效果。有任何想法吗?这是我的层次结构,ScrollView,TableLayout

  <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>
Run Code Online (Sandbox Code Playgroud)

Mar*_*ues 5

尝试将 textview 的宽度设置为 wrap_content,删除 layout_column=1(不需要,afaik),并将edittext 的高度和宽度设置为 wrap_content。

无论如何,让一个 textview 填充屏幕并在其右侧有一个宽度至少为 120dip 的 edittext 是很奇怪的。如果您坚持使用 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>
Run Code Online (Sandbox Code Playgroud)

您需要调整 EditText 的位置,TextView 将贴在其左侧。