我在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>
答案 0 :(得分:0)
您是否在设置布局参数后尝试放置requestLayout()?