2016-07-02 2 views
0

У меня проблемы с моими макетами в моем приложении. После изменения текста TextView (динамически) до некоторого длинного текста он накладывает мой TableLayout. Надеюсь, вы можете помочь мне определить, как перемещать TableLayout в видимый диапазон.Layout overlaying another layout после динамического изменения

UPD. Мой плохой, что я не определил, какой TextView я изменил. Это TextView над TableLayout с id = textView.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.home.myapp1.MainActivity" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="vertical" 
     android:text="Hello world!" 
     android:singleLine="false"/> 

    <TableLayout android:layout_marginTop="10dp" 
     android:id="@+id/table" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:stretchColumns="*"> 
     <TableRow android:padding="5dp"> 
      <TextView android:text="Валюта" android:gravity="center_horizontal"/> 
      <TextView android:text="Покупка" android:gravity="center_horizontal"/> 
      <TextView android:text="Продажа" android:gravity="center_horizontal"/> 
     </TableRow> 
    </TableLayout> 
</LinearLayout> 

ответ

0

Я попытался использовать заданный макет xml и динамически изменил текст текстового представления (для целей тестирования я изменил текст на нажатие кнопки, который я разместил ниже TableLayout), но он работал нормально до тех пор, пока TextView не будет покрывать всю высоту экрана. Если для вашего текста нет ограничений, тогда следует использовать ScrollView в качестве родителя вашего макета. Так попробуйте заменить контент XML с содержанием ниже, и это может решить проблему:

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.home.myapp1.MainActivity" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="vertical" 
     android:text="Hello world!" 
     android:singleLine="false"/> 

    <TableLayout android:layout_marginTop="10dp" 
     android:id="@+id/table" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:stretchColumns="*"> 
     <TableRow android:padding="5dp"> 
      <TextView android:text="Валюта" android:gravity="center_horizontal"/> 
      <TextView android:text="Покупка" android:gravity="center_horizontal"/> 
      <TextView android:text="Продажа" android:gravity="center_horizontal"/> 
     </TableRow> 
    </TableLayout> 
</LinearLayout> 

</ScrollView> 
1

Try веса и одной линии TextView Как это ........

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 

     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/textView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scrollbars="vertical" 
      android:text="Hello world!" 
      android:singleLine="false"/> 

     <TableLayout android:layout_marginTop="10dp" 
      android:id="@+id/table" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:stretchColumns="*"> 
      <TableRow android:padding="5dp" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="3"> 
       <TextView android:text="Валюта" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:maxLines="1" 
        android:layout_weight="1" android:gravity="center_horizontal"/> 
       <TextView 

        android:text="Покупка" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:maxLines="1" 
        android:gravity="center_horizontal"/> 
       <TextView android:text="Продажа" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:maxLines="1" 
        android:gravity="center_horizontal"/> 
      </TableRow> 
     </TableLayout> 
    </LinearLayout> 

** Здесь **

android:maxLines="1" 

Используется для зрения, сделайте хорошо, если вы не дадите это, чем макет, сделайте плохой, когда длина текста много слов ... или вы также указали длину текста.

+0

Я меняющийся TextView выше TableLayout –

+0

мне не нужно ограничивать MaxLines из TextView, наоборот мне нужно отобразить весь текст TextView, но всякий раз, когда он превышает 1 строку, он накладывает вид снизу, поэтому мне нужно решение для перемещения этого наложенного вида в видимый диапазон в моей Activity. –

+0

Вы можете взять андроид: maxLength = "20" Вместо максимальных строк Исправить диапазон –