2015-10-11 63 views
1

我正在做一個項目,我必須在地圖上顯示箭頭,這是一張圖片。當使用不同的屏幕時,底圖將伸展或壓縮。但是箭頭的位置仍然保持不變。是否有任何方法讓箭頭跟隨地圖?有沒有辦法根據屏幕大小改變圖像的位置?

enter image description here

圖像1是當我使用更小的屏幕,而圖像2是當我使用較大scrren

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" 
android:layout_height="fill_parent" 

tools:context="com.example.window8.rescape.Escape" 
android:id="@+id/main" 

> 

<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/background" 
    android:background="@drawable/basebase" /> 

<ImageView 
    android:layout_width="50dp" 
    android:layout_height="60dp" 
    android:id="@+id/pointer" 
    android:layout_gravity="bottom" 
    android:background="@drawable/pointer" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginBottom="198dp" /> 

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"> 

     <ImageView 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:id="@+id/imageView2" 
      android:background="@drawable/arrow4" 
      android:layout_marginLeft="68px" /> 

     <ImageView 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:id="@+id/imageView" 
      android:background="@drawable/arrow2" 
      android:layout_marginLeft="80px" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"></LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"></LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"></LinearLayout> 
</LinearLayout> 

</RelativeLayout> 
+0

你希望這些箭頭指向退出?僅剩權利。或者你有其他情況?我提供的答案解決了一個普遍問題。如果你想要的只是指向左上角和右上角,你的解決方案就容易得多。只需在框架佈局中添加箭頭,然後爲左上角和右上角的箭頭設置佈局重力! – hasan83

回答

0

對於包含的箭頭添加2個LinearLayouts所述的LinearLayout。一個在第一個箭頭之前,另一個在箭頭之間。此外,增加重量和父的LinearLayout如下:

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:layout_weightSum="100"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="0dp" 
     android:layout_weight="10" 
     android:layout_height="fill_parent"/> 

    <ImageView 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:id="@+id/imageView2" 
     android:background="@drawable/arrow4" 
     android:layout_marginLeft="68px" /> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="0dp" 
     android:layout_weight="10" 
     android:layout_height="fill_parent"/> 

    <ImageView 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:id="@+id/imageView" 
     android:background="@drawable/arrow2" 
     android:layout_marginLeft="80px" /> 
</LinearLayout> 

現在,你需要直到你找到想要的那些與權重值打了2個線性佈局。

+0

它的工作,但必須非常耐心haha –

0

把你的箭一的FrameLayout內,並添加layout_gravity屬性,對他們說:

<FrameLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1"> 

    <ImageView 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:id="@+id/imageView2" 
     android:background="@drawable/arrow4" 
     android:layout_marginLeft="68px" 
     android:layout_gravity="top|left" /> 

    <ImageView 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:id="@+id/imageView" 
     android:background="@drawable/arrow2" 
     android:layout_marginRight="68px" 
     android:layout_gravity="top|right" /> 
</FrameLayout> 
+0

仍然相同的結果 –

+0

你做錯了什麼 – hasan83

+1

我覺得你的方法會更容易,但duno爲什麼不能繼續工作 –

相關問題