It seems like I cannot get or set any position or amount of scroll in my simple layout:
// Relative layout - main_layout
<HorizontalScrollView
android:id="@+id/MenuScroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="48dp"
android:orientation="horizontal"
android:layout_gravity="center"
android:padding="0dp" >
<Button
android:id="@+id/button1"
android:layout_width="150dp"
android:layout_height="fill_parent" />
<Button
android:id="@+id/button2"
android:layout_width="150dp"
android:layout_height="fill_parent" />
<Button
android:id="@+id/button3"
android:layout_width="150dp"
android:layout_height="fill_parent" />
<Button
android:id="@+id/button4"
android:layout_width="150dp"
android:layout_height="fill_parent" />
<Button
android:id="@+id/button5"
android:layout_width="150dp"
android:layout_height="fill_parent" />
</LinearLayout>
</HorizontalScrollView>
// End of RelativeLayout - main_layout
In mine, MainActivityI want to get the position of any button inside HorizontalScrollViewand scroll it to this position. At the moment, I canโt get the left value (always 0), and if I try scrollTo HorizontalScrollView, it just doesnโt, no matter what the value is for x or y.
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
final Button button3 = (Button)findViewById(R.id.button3);
Rect rectf = new Rect();
button3.getLocalVisibleRect(rectf);
Log.i("Left: ", String.valueOf(rectf.left));
HorizontalScrollView MenuScroll = (HorizontalScrollView)findViewById(R.id.MenuScroll);
MenuScroll.scrollTo(100, MenuScroll.getBottom());
}
}
So, as I said, I canโt get the left position for my button, and either I can go to some X position in mine HorizontalScrollView. Is it possible?
source
share