我在ScrollView中点击了“TextView1”,我需要让屏幕在文本中低到“TextView2”文本。
答案 0 :(得分: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]);
}
}
}
享受!