Android 单击TextView1可跳转到滚动视图中的TextView2
我使“TextView1”在ScrollView中可点击,我需要将文本中的屏幕降低到“TextView2”文本。这是我的布局:Android 单击TextView1可跳转到滚动视图中的TextView2,android,text,scroll,textview,Android,Text,Scroll,Textview,我使“TextView1”在ScrollView中可点击,我需要将文本中的屏幕降低到“TextView2”文本。这是我的布局: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/activity_main_scrollview" android:layout_width="match_parent" android:layout_height
<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]);
}
}
}
享受吧我听懂了吗?您的意思是,您想在textview1单击操作时滚动到textview2吗?“让屏幕变得更低”是什么意思?等着回答,没错。你很明白。这就像在上面你有所有的歌曲标题,下面你有所有的歌词标题。当我在开始时点击一首歌的名字时,我希望屏幕转到我点击的歌的标题。欢迎来到stack overflow。在这里,你不只是写你想要的。您还必须告诉我们您为解决问题付出了哪些努力,哪些没有奏效。还可能添加一个示例代码。阅读faq了解详细信息。感谢你们的帮助。我完全按照你写的做了,而且效果很好。我试着和OnClickListener谈谈,但试了几个小时后,我不再固执了,在这里问。这个代码看起来不多,但对我来说,它是一个生命的救星。我现在将阅读常见问题,并感到自豪,因为我相信这里有很多有用的东西。再次感谢!!如果我的回答对你有用,请+1!