xml - How to Center ImageView in HorizontalScroll View Android -
i have been trying center large wallpaper of 3000px x 1500px (roughly) when loaded show center of image , user can scroll left or right view rest. have looked @ few examples , doesn't seem lands on left of image!
i need pair of eyes point me in right direction.
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fab="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/black"> <horizontalscrollview android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="none" > <linearlayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_centerhorizontal="true" > <imageview android:id="@+id/imgfullscreen" android:layout_width="match_parent" android:layout_height="wrap_content" /> </linearlayout> </horizontalscrollview> </relativelayout>
thanks in advance!
first need set linearlayout , imageview width "wrap_content" , measure scollview , it's width , after need screen size scrollto , scroll middle
middle offset = (scrollview width - screen width ) / 2
Comments
Post a Comment