Tôi đang cố gắng đặt vị trí của scrollview ngang sao cho nó tương ứng với nút được đẩy. Tôi đã cố gắng sử dụng này để thiết lập nó không thành công:Vị trí thiết lập Android của scrollbox hortizontal
HorizontalScrollView hsv = (HorizontalScrollView)findViewById(R.id.ScrollView);
int x, y;
x = hsv.getLeft();
y = hsv.getTop();
hsv.scrollTo(x, y);
Điều này dẫn đến không có gì, các scrollview không bị ảnh hưởng. Các xml:
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@null"
android:scrollbars="none" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button
android:layout_width="100dp"
android:layout_height="fill_parent"
android:layout_marginBottom="-5dp"
android:text="btn0"
android:id="@+id/btn0"
android:background="@drawable/yellow_btn" />
<Button
android:layout_width="100dp"
android:layout_height="fill_parent"
android:layout_marginBottom="-5dp"
android:background="@drawable/yellow_btn"
android:text="bnt1"
android:id="@+id/btn1" />
<Button
android:layout_width="100dp"
android:layout_height="fill_parent"
android:layout_marginBottom="-5dp"
android:background="@drawable/yellow_btn"
android:text="btn2"
android:id="@+id/btn2" />
<Button
android:layout_width="100dp"
android:layout_height="fill_parent"
android:layout_marginBottom="-5dp"
android:background="@drawable/yellow_btn"
android:text="btn3"
android:id="@+id/btn3" />
<Button
android:layout_width="100dp"
android:layout_height="fill_parent"
android:layout_marginBottom="-5dp"
android:background="@drawable/yellow_btn"
android:text="btn4"
android:id="@+id/btn4" />
<Button
android:layout_width="100dp"
android:layout_height="fill_parent"
android:layout_marginBottom="-5dp"
android:background="@drawable/yellow_btn"
android:text="btn5"
android:id="@+id/btn5" />
</LinearLayout>
</HorizontalScrollView>
Vì vậy, nếu nút thứ 5 được đẩy (đó là offscreen) khi hoạt động mới bắt đầu tôi muốn thiết lập các quan điểm mới để các scrollview ngang là tất cả các cách ở bên phải so với bắt đầu tất cả các con đường bên trái.
Làm cách nào để đặt vị trí của chế độ xem cuộn ngang?
Tôi đã thử cài đặt này ngay sau khi tôi đặt bố cục nhưng không có gì xảy ra. Bất kỳ ý tưởng nào khác? – Nick
Tôi đã chỉnh sửa câu trả lời của mình và thêm giải thích đầy đủ về giải pháp. – theisenp
Genius! Cảm ơn câu trả lời tuyệt vời. – Nick