scroll vertically only

This commit is contained in:
Frank Morgner
2015-10-03 03:40:57 +02:00
parent 97074650b7
commit 612db6f2f9
2 changed files with 16 additions and 30 deletions

View File

@@ -28,13 +28,13 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.Layout;
import android.text.method.ScrollingMovementMethod;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@@ -42,6 +42,7 @@ import android.widget.Toast;
public class MainActivity extends ActionBarActivity { public class MainActivity extends ActionBarActivity {
private TextView textViewVPCDStatus; private TextView textViewVPCDStatus;
private ScrollView scrollView;
private BroadcastReceiver bReceiver = new BroadcastReceiver() { private BroadcastReceiver bReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@@ -59,14 +60,7 @@ public class MainActivity extends ActionBarActivity {
textViewVPCDStatus.append(getResources().getString(R.string.status_error) + ": " + error + "\n"); textViewVPCDStatus.append(getResources().getString(R.string.status_error) + ": " + error + "\n");
if (rapdu != null) { if (rapdu != null) {
textViewVPCDStatus.append(getResources().getString(R.string.status_rapdu) + ": " + rapdu + "\n"); textViewVPCDStatus.append(getResources().getString(R.string.status_rapdu) + ": " + rapdu + "\n");
Layout layout = textViewVPCDStatus.getLayout(); scrollView.fullScroll(View.FOCUS_DOWN);
if (layout != null) {
int scrollAmount = layout.getLineTop(textViewVPCDStatus.getLineCount()) - textViewVPCDStatus.getHeight();
if (scrollAmount > 0)
textViewVPCDStatus.scrollTo(0, scrollAmount);
else
textViewVPCDStatus.scrollTo(0, 0);
}
} }
if (deselect != null) if (deselect != null)
textViewVPCDStatus.append(getResources().getString(R.string.status_disconnected) + ": " + deselect + "\n"); textViewVPCDStatus.append(getResources().getString(R.string.status_disconnected) + ": " + deselect + "\n");
@@ -96,7 +90,7 @@ public class MainActivity extends ActionBarActivity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
textViewVPCDStatus = (TextView) findViewById(R.id.textViewLog); textViewVPCDStatus = (TextView) findViewById(R.id.textViewLog);
textViewVPCDStatus.setMovementMethod(new ScrollingMovementMethod()); scrollView = (ScrollView) findViewById(R.id.scrollView);
SharedPreferences settings = getSharedPreferences(PREFS, 0); SharedPreferences settings = getSharedPreferences(PREFS, 0);
if (settings.getInt(PREF_LASTVERSION, 0) != BuildConfig.VERSION_CODE) { if (settings.getInt(PREF_LASTVERSION, 0) != BuildConfig.VERSION_CODE) {
showStartupMessage(); showStartupMessage();

View File

@@ -1,29 +1,21 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:keepScreenOn="true" android:keepScreenOn="true"
android:orientation="vertical"
tools:context="com.vsmartcard.remotesmartcardreader.app.MainActivity"> tools:context="com.vsmartcard.remotesmartcardreader.app.MainActivity">
<HorizontalScrollView <ScrollView
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_alignParentRight="true" android:id="@+id/scrollView">
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/textViewLog" android:id="@+id/textViewLog"
android:typeface="monospace" /> android:typeface="monospace" />
</HorizontalScrollView> </ScrollView>
</RelativeLayout> </LinearLayout>