2017-06-16 111 views
1

在我的應用程序中,我想添加一個圖像在另一個圖像上,當用戶放大圖像時,它也應該移動,就像谷歌地圖。 請各位看看下面的圖像,我想將標誌動態在android中的另一個圖像上添加圖像

enter image description here

請指點更好的方式來完成這個任務。

+0

您可以使用畫布 – jagapathi

+0

@jagapathi如何在圖片上添加畫布 – deep

回答

0

解決方案(XML):

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@drawable/t" /> 
    <item android:drawable="@drawable/tt" /> 
</layer-list> 

解決方案(動態):

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="maxdorid.ir.MainActivity"> 


    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:srcCompat="@mipmap/ic_launcher" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" 
     android:id="@+id/imageView" /> 
</RelativeLayout> 


public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Resources r = getResources(); 
     Drawable[] layers = new Drawable[2]; 
     layers[0] = r.getDrawable(R.drawable.ic_alarm_off_black_24dp); 
     layers[1] = r.getDrawable(R.drawable.ic_apps_black_24dp); 
     LayerDrawable layerDrawable = new LayerDrawable(layers); 
     ImageView imageView= (ImageView) findViewById(R.id.imageView); 
     imageView.setImageDrawable(layerDrawable); 
    } 
} 

如果你使用一個以上的圖像:

private Bitmap overlay(Bitmap bmp1, Bitmap bmp2,int x,int y) { 
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); 
    Canvas canvas = new Canvas(bmOverlay); 
    canvas.drawBitmap(bmp1, new Matrix(), null); 
    canvas.drawBitmap(bmp2, x,y, null); 
    return bmOverlay; 
} 
+0

不工作,當我使用它時應用程序崩潰。 – deep

+0

哪種方法xml或動態? –

+0

編輯我的答案。再檢查一遍。 –

0

使用相對佈局,背景和地點圖像作爲相對佈局的組成部分,使用相對佈局參數調整屏幕上的圖像位置一個適用於相對佈局本身的縮放

相關問題