I'm suffering some problems with my layouts in my app. After changing text of TextView (dynamically) to some long text, it overlays my TableLayout. Hope you can help me to determine how to move TableLayout to visible range.
UPD. My bad, that I'm not defined which TextView I've changed. It's TextView above TableLayout with 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>
I tried using the given layout xml and changed the text of textview dynamically (for testing purpose I changed text on button click which I placed below the TableLayout) but it was working fine until and unless TextView covers the whole screen height. If there is no limit for your textview, then should use ScrollView as the parent of your layout. So try replacing your xml content with below content and it may solve your issue:
<?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>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments