/ / TextView1, klikając, aby przejść do TextView2 w ScrollView - Android, tekst, przewijanie, przeglądanie tekstu

TextView1 przez kliknięcie, aby przejść do TextView2 w ScrollView - android, tekst, przewijanie, widok tekstowy

Umożliwiłem kliknięcie „TextView1” w ScrollView i muszę sprawić, aby ekran obniżył się znacznie w tekście do tekstu „TextView2”.

Odpowiedzi:

0 dla odpowiedzi № 1

Oto mój układ:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
android:id="@+id/textViewTitle"
android:onClick="doClick"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/padding_medium"
android:layout_marginBottom="1500dp"
android:text="@string/hello_world" />

<TextView
android:id="@+id/textViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/padding_medium"
android:text="sdfasiufhadifhissipaghuopghshgiahipuhguiashguipahguiphiughsdupaghapsghasuipghasughpgh" />

</LinearLayout>

A to jest mój kod:

public class MainActivity extends Activity {

private ScrollView scrollView;
private TextView textViewAim;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

scrollView =  (ScrollView) findViewById(R.id.activity_main_scrollview);
textViewAim = (TextView)   findViewById(R.id.textViewText);
}

public void doClick(View view){
if (view.getId() == R.id.textViewTitle) {
int[] location = new int[2];
textViewAim.getLocationOnScreen(location);
scrollView.scrollTo(location[0], location[1]);
}
}
}

cieszyć się!