2012-07-24 2 views
0

Android 타일보기에 3 x 3 격자의지도 타일 (이미지)이 있습니다. 이 이미지는 동적으로로드되며 설정된 레이아웃만큼 상대 레이아웃을 이동하려고합니다 (항상 음수가됩니다). 이 HTML에서 성공적으로 할 수 있지만 안드로이드에서 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> 

답변

0

당신이 레이아웃 PARAM을 설정 한 후 requestLayout()를 넣어 시도 했습니까?

+0

트릭을 해 주셔서 감사합니다. 나는 이런 일을해야하는지 궁금해했습니다. –

관련 문제