0

Мое намерение состоит в том, чтобы сделать мой TextView прокручивать, вкладывая его внутрь ScrollView (хотя я знаю, что TextView можно прокручивать по себе (без необходимости родитель ScrollView), я хотел бы сделать это в таким образом :)) и заполните ScrollView всю ширину экрана.Вложение в Scrollview внутри TableRow

Макет в следующем коде работает, но ScrollView не заполняет всю ширину экрана. Однако его родительский TableRow заполняет всю ширину.

Я попытался подстановки значений из android:layout_widthScrollView с fill_parent, match_parent и wrap_content, но ни один из них не полностью заполняя ширину.

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/activity_my"> 

    <TableRow> 
     <EditText android:id="@+id/edit_message" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:hint="@string/edit_message" 
      android:layout_weight="1"/> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="@string/button_send" 
      android:onClick="sendMessage"/> 
    </TableRow> 

    <TableRow> 
     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scrollbars="vertical" 
      android:fillViewport="true"> 
      <TextView 
       android:id="@+id/message_box" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" /> 
     </ScrollView> 
    </TableRow> 

</TableLayout> 

ответ

1

Я нашел решение! Я добавил android:layout_weight="1" в ScrollView.

<ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="vertical" 
     android:layout_weight="1" 
     android:fillViewport="true"> 
     <TextView 
      android:id="@+id/message_box" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 
</ScrollView>