Android ビューに 3 x 3 グリッドのマップ タイル (画像) があります。これらの画像は動的に読み込まれ、相対レイアウトを一定量移動したい (これは常に負になります)。HTMLでこれを正常に実行できますが、Androidの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>