2016-11-03 44 views
1

我有一個飛機內部的藍圖,它可以顯示每個座位和區域的相關信息,作爲點擊吐司。該按鈕連接到圖像本身,因爲我想要的佈局是可縮放和可平移,這點我是可以用的獲取Imageview不同區域的特定像素參數?

https://github.com/Lukle/ClickableAreasImages

但是幫助這樣做,因爲由我們將其定義可點擊的方法區域被以下面的格式硬編碼(如在鏈接看到上面更詳細):

// Define your clickable areas 
// parameter values (pixels): (x coordinate, y coordinate, width, height) and assign an object to it 

     clickableAreas.add(new ClickableArea(500, 200, 125, 200, new Character("Homer", "Simpson"))); 
     clickableAreas.add(new ClickableArea(600, 440, 130, 160, new Character("Bart", "Simpson"))); 

此方法要求我知道確切的x,y座標和寬度和點擊區域的高度,這是作爲我的應用程序所需的一個重要方面,我面臨的一個重大挑戰是由於衆多的應用程序的可點擊準確性圖像視圖中的可點擊區域。

因此,我的問題是,是否有通過layout.xml標籤的方式或者其他任何地方,我可以畫領域,並提取其對應的x,y座標和每個可點擊區域的寬度和高度?

任何幫助,非常感謝!

編輯: 在建議的https://stackoverflow.com/a/17807469/7034521的幫助下,我能夠裁剪以在將DrawView代碼附加到我的線性佈局後查找座標。 但是,在ClickableAreasImages中使用座標時,裁剪區域的座標不對應於可點擊區域。我已經確定將線性佈局和圖像視圖的寬度和高度都設置爲'fill_parent',所以我不確定是什麼錯誤。下面是從我的項目的一些附加代碼,我認爲可能是相關的:

在drawView函數(添加下面的部分https://stackoverflow.com/a/17807469/7034521):

case MotionEvent.ACTION_UP: 
       while (isNotPrinted) { 

        int x = colorballs.get(0).getX(); 
        int y = colorballs.get(0).getY(); 
        int width = colorballs.get(2).getX() - colorballs.get(0).getX(); 
        int height = colorballs.get(1).getY() - colorballs.get(0).getY(); 
        Log.i("x, y, width, height:",Integer.toString(x) + ", " + Integer.toString(y) + 
          ", "+ Integer.toString(width) + ", "+Integer.toString(height)); 
        isNotPrinted = false; 
       } 

       break; 

activity.xml:

<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/imageView3" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" 
    android:src="@drawable/b777_212b_1" /> 

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:id="@+id/myLinearLayout" 
    android:layout_alignRight="@+id/imageView3" 
    android:layout_alignEnd="@+id/imageView3"></LinearLayout> 

activity.java:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_coordinates_tester); 


     LinearLayout layout = (LinearLayout) findViewById(R.id.myLinearLayout); 
     DrawView myView = new DrawView(this); 
     myView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); 
     // myView.setText("Added myView"); 
     layout.addView(myView); 

     // Add image 
     ImageView image = (ImageView) findViewById(R.id.imageView3); 
     image.setImageResource(R.drawable.b777_212b_1); 

    } 
+0

這個計算器的問題看'ImageView的#getImageMatrix':*「返回該視圖的可選矩陣。 「* – pskink

回答

0

基本上在你的問題,你需要一個攝像頭,在你的圖像移動,所以你可以根據自己究竟在Android上的唯一區別的圖像裁剪使用相同的技術調整矩形你不會裁剪圖像,但得到的是從點相機視圖

看到詳細 How to create a resizable rectangle with user touch events on Android?

+0

謝謝,這是我需要的。但是,裁剪的座標與ClickableAreasImages中使用的座標不一致,即使我試圖對齊線性佈局和圖像視圖。我已經編輯了我的帖子以獲得更多深入信息。不知道有什麼問題。 –

相關問題