我一直试图将3000px x 1500px(大致)的大型壁纸置于加载显示图像中心的位置,然后用户可以向左或向右滚动以查看其余部分。我看了几个例子,它似乎并没有帮助它总是落在图像的左边!
我只需要另一双眼睛指向正确的方向。
<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>
提前致谢!
答案 0 :(得分:0)
首先,滚动视图内的布局应为
android:orientation="horizontal"
并包装widht和height
的内容最后你想要的是以中心的滚动视图开始活动。 您可以通过编程方式执行
之类的操作int centerX = scrollView.getChildAt(0).getWidth()/2;
int centerY = scrollView.getChildAt(0).getHeight()/2;
scrollView.scrollTo(centerX, centerY);
例如在您的活动的onCreateView
中答案 1 :(得分:0)
首先,您需要将linearlayout和imageView宽度设置为&#34; wrap_content&#34; 然后measure 你的scollView并获得它的宽度,之后你需要获得screen size scrollTo,然后滚动到中间
middle Offset = (scrollView width - screen width ) / 2