I am logging my app into ScrollView using method
addLog(View view, String what)
New lines should be appended to top of ScrollView so user can see all of them starting from nr1 (like at Picture 3)
Picture 1 - after start - previous lines are gone - WHAT IS WRONG ? View is not scrollable
Picture 2 - screen rotate - all OK, view is scrollable
Picture 3 - screen rotated again to original position - all OK, view is scrollable
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
tools:context="cz.nielsenadmosphere.androiddemo.NlsCZdemo1.MainActivity">
<LinearLayout
android:id="@+id/screen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@color/primary"
android:orientation="vertical">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/player_view"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_gravity="center"
app:use_controller="false">
</com.google.android.exoplayer2.ui.SimpleExoPlayerView>
</LinearLayout>
<LinearLayout
android:id="@+id/seekBarLL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/screen"
android:layout_centerHorizontal="true"
android:background="@color/primary_dark"
android:gravity="center_horizontal">
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="30dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/btns"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/seekBarLL"
android:layout_centerHorizontal="true"
android:background="@color/primary"
android:orientation="horizontal">
<Button
android:id="@+id/btn_play"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="@string/txt_play" />
<Button
android:id="@+id/btn_pause"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="@string/txt_pause" />
<Button
android:id="@+id/btn_end"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="@string/txt_end" />
</LinearLayout>
<LinearLayout
android:id="@+id/labels"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btns"
android:background="@color/primary_light"
android:orientation="horizontal"
>
<TextView
android:id="@+id/txt_label1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="playHead:"
android:textColor="@color/secondary_text"
android:padding="5dp"/>
<TextView
android:id="@+id/txt_playtime"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:gravity="left"
android:text="0"
android:textColor="@color/primary_text"
android:padding="5dp"/>
<TextView
android:id="@+id/txt_label2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="status:"
android:textColor="@color/secondary_text"
android:padding="5dp"/>
<TextView
android:id="@+id/txt_playStatus"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:gravity="left"
android:text="null"
android:textColor="@color/primary_text"
android:padding="5dp"/>
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView"
android:layout_below="@+id/labels"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
<!-- height must be wrap_content -->
<TextView
android:id="@+id/scrollViewText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dip"
android:textSize="12sp"
>
</TextView>
</ScrollView>
</RelativeLayout>
java.class
public class displayLogScreen extends Activity{
static int logPosition = 0;
static String logTotal = "";
static String logPart = "";
private static String TAG = "displayLogScreen";
static ScrollView scrollView;
public static void addLog(View view, String what) {
Log.i(TAG, "addLog what=" + what);
Calendar logCal = Calendar.getInstance();
DecimalFormat mFormat= new DecimalFormat("00");
String logTime = logCal.get(Calendar.YEAR) + "." + mFormat.format(logCal.get(Calendar.MONTH)+1) + "." + mFormat.format(logCal.get(Calendar.DATE))+ " " + mFormat.format(logCal.get(Calendar.HOUR_OF_DAY)) + ":" + mFormat.format(logCal.get(Calendar.MINUTE)) + ":" + mFormat.format(logCal.get(Calendar.SECOND));
// just for test
what = "fooo";
logPosition ++;
logPart = "("+ logPosition + ") " + logTime + " " + what + "\n";
logTotal = logPart + logTotal;
// add log to ScrollView
TextView txt_logs = (TextView) view.findViewById(R.id.scrollViewText);
txt_logs.setText(logTotal);
// if Error - add Toast
// if (what.substring(0,5).equals("ERROR"))
// Toast.makeText(view.getContext() , what, Toast.LENGTH_SHORT).show();
}
}