0
我在Android視圖上有3 x 3的地圖貼圖(圖像)網格。這些圖像是動態加載的,然後我想將相對佈局移動一定的數量(這將始終爲負數)。我可以在HTML中成功完成此操作,但是當我在Android的RelativeLayout上嘗試它時,它無法工作。具有負偏移的RelativeLayout不起作用
我使用以下,但它不工作的嘗試:
View view = this.findViewById(R.id.mapContrainer);
RelativeLayout.LayoutParams head_params = (RelativeLayout.LayoutParams)view.getLayoutParams();
head_params.setMargins(leftOffset, topOffset, 0, 0);
view.setLayoutParams(head_params);
這裏是我的我的佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location"
android:paddingBottom="10dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="current location"
android:paddingBottom="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ZoomControls
android:id="@+id/zoomControls1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<ImageView
android:id="@+id/locationIcon"
android:layout_width="32dp"
android:layout_height="32dp"
android:scaleType="fitXY"
android:layout_centerInParent="true"
android:src="@drawable/ic_map_person"
/>
<RelativeLayout
android:id="@+id/mapContrainer"
android:layout_width="768dp"
android:layout_height="768dp"
android:layout_marginRight="-400dp"
android:layout_marginBottom="-400dp"
>
<ImageView
android:id="@+id/mapImage1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_location_light" />
<ImageView
android:id="@+id/mapImage2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/mapImage1"
android:src="@drawable/ic_location_light" />
<ImageView
android:id="@+id/mapImage3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/mapImage2"
android:src="@drawable/ic_location_light" />
<ImageView
android:id="@+id/mapImage4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_location_light"
android:layout_below="@+id/mapImage1"
android:layout_alignLeft="@+id/mapImage1"
/>
<ImageView
android:id="@+id/mapImage5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_location_light"
android:layout_below="@+id/mapImage1"
android:layout_toRightOf="@+id/mapImage4"
/>
<ImageView
android:id="@+id/mapImage6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_location_light"
android:layout_below="@+id/mapImage1"
android:layout_toRightOf="@+id/mapImage5"
/>
<ImageView
android:id="@+id/mapImage7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_location_light"
android:layout_below="@+id/mapImage4"
android:layout_alignLeft="@+id/mapImage1"
/>
<ImageView
android:id="@+id/mapImage8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_location_light"
android:layout_below="@+id/mapImage4"
android:layout_toRightOf="@+id/mapImage7"
/>
<ImageView
android:id="@+id/mapImage9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_location_light"
android:layout_below="@+id/mapImage4"
android:layout_toRightOf="@+id/mapImage8"
/>
</RelativeLayout>
</RelativeLayout>
<include
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="bottom|center_horizontal"
layout="@layout/menu_layout" />
</LinearLayout>
謝謝你的訣竅。我一直在想,如果我需要做這樣的事情。 – 2012-07-25 07:39:41