-2

我在 ScrollView 中使“TextView1”可点击,我需要使屏幕在文本中降低到“TextView2”文本。

4

1 回答 1

0

这是我的布局:

<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>

这是我的代码:

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]);
        }
    }
}

请享用!

于 2012-09-18T10:37:40.550 回答