0
我想要顯示一個始終位於設備物理中心的點,即使我在滾動視圖中滾動其周圍的內容時也是如此。這是我目前的代碼,但是這裏缺少點,因爲我不知道該把它放在哪裏。 scrollposition只能通過代碼設置,所以如果居中的元素阻止了滾動視圖,那麼它就不會成爲問題。在滾動視圖中居中當前視口上的元素
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:deviceIds="wear_square"
android:gravity="center">
<android.support.v4.widget.NestedScrollView
android:id="@+id/vertsv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<HorizontalScrollView
android:id="@+id/horisv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/map" />
</LinearLayout>
</HorizontalScrollView>
</android.support.v4.widget.NestedScrollView>
解決方案:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:deviceIds="wear_square">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/vertsv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<HorizontalScrollView
android:id="@+id/horisv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/map" />
</LinearLayout>
</HorizontalScrollView>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/ic_my_location_black_24dp" />
</RelativeLayout>
爲什麼你不能從onDraw()中繪製這個點,而不是從xml構建令人困惑的佈局? –
希望你只集中你的形象?請解釋一下。 –
最簡單的方法是將你的點放在滾動視圖之外。在這種情況下,您可以根據需要對齊。 –