2014-01-22 14 views
2

我有一個名爲「Dress」的RelativeLayout,它帶有WRAP_CONTENT的LayoutParams。它內部的所有內容都是ImageView,因此它與ImageView的大小相同。當我在OnCreate中添加一個視圖到RelativeLayout的,就像這樣:向RelativeLayout添加視圖更改其大小

photoSorter = new MultitouchImagesView(this.getApplicationContext()); 
     RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
     ((ViewGroup) findViewById(id.Dress)).addView(photoSorter, params); 

的RelativeLayout的稱爲着裝改變大小,採取了整個RootView,基本上整個活動,減去動作條。

我拍攝了服飾佈局的截圖。所以,當photoSorter在RootLayout(不是連衣裙佈局)是這樣的:

photoSorter = new MultitouchImagesView(this.getApplicationContext()); 
     RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
     addContentView(photoSorter, params); 

佈局連衣裙是正確的大小,我得到這個截圖這就是我想要的:

enter image description here

但我需要在服飾佈局中使用PhotoSorter,以便我可以將其包含在我的屏幕截圖中,而不是黑色條。當我photoSortr添加到連衣裙佈局是這樣的:

photoSorter = new MultitouchImagesView(this.getApplicationContext()); 
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
      ((ViewGroup) findViewById(id.Dress)).addView(photoSorter, params); 

它使着裝佈局佔據整個屏幕,這樣的着裝佈局的截圖如下:

enter image description here

這裏是我的代碼進行屏幕截圖:

public Bitmap takeScreenshot() { 
     View v = findViewById(R.id.Dress); 
     v.setDrawingCacheEnabled(true); 
     return v.getDrawingCache(); 
    } 

這裏是我的活動XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:longClickable="true" 
    android:onClick="deleteImage" 
    android:background="@android:color/transparent" 
    tools:context=".MainActivity" > 

    <RelativeLayout 
     android:id="@+id/Dress" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@android:color/transparent" > 

    <ImageView 
     android:id="@+id/imageViewDress" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:adjustViewBounds="true" 
     android:background="#00CED1" 
     android:padding="10dp" 
     android:scaleType="centerInside" /> 

    </RelativeLayout> 

    <com.edmodo.cropper.CropImageView 
    xmlns:custom="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/CropImageView" 
    android:background="@android:color/transparent" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
</RelativeLayout> 

此外,當我將com.edmodo.cropper.CropImageView添加到DressLayout時,它使Dress Dress佔據整個活動。因此,向Dress Layout添加任何內容都會使其變得更大。

如何在不使服裝佈局佔據整個活動尺寸的情況下將照片服裝添加到服裝佈局?

謝謝。

回答

1

我通過嘗試XML的東西管理。關鍵是要將dress與imageViewDress對齊,我可以將其他兩邊對齊得更徹底,而不僅僅是底部。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:longClickable="true" 
     android:background="@android:color/transparent" 
     tools:context=".DressingRoomActivity" > 

     <RelativeLayout 
      android:id="@+id/DressBig" 
      android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true"> 

      <ImageView 
      android:id="@+id/imageViewDress" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:adjustViewBounds="true" 
      android:scaleType="centerInside" /> 

      <RelativeLayout 
      android:id="@+id/Dress" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@android:color/transparent" 
      android:layout_alignBottom="@+id/imageViewDress" 
      android:layout_centerInParent="true" > 
      </RelativeLayout> 

     </RelativeLayout> 

     <com.edmodo.cropper.CropImageView 
     xmlns:custom="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/CropImageView" 
     android:background="@android:color/transparent" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    </RelativeLayout> 

此XML,然後加入photoSorter扮靚編程,然後採取DressBig的屏幕截圖。

0

下應該工作

<RelativeLayout android:id="@+id/Dress" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="..."> 

<ImageView 
    android:id="@+id/imageViewDress" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    ... 
    android:scaleType="fitXY" /> 

編輯:

所以它奠定了在其它內容,如果這就是你想要的,您可以添加下面的規則,你PARAMS。這是我第三次試圖弄清楚你要求什麼,如果這不是你所需要的,你必須自己弄明白,因爲你懶惰,不會做草圖來嘗試和解釋清楚你想要如何佈局

params.addRule(RelativeLayout.CENTER_IN_PARENT); 
+0

謝謝:)我只會解釋關於我的應用程序的這些事情。改變圖像比例或裁剪是不可能的。這不會發生,因爲我不想讓圖像適合屏幕尺寸。它走到屏幕的寬度,然後高度就停在停止的地方。所以它會達到屏幕尺寸的90%左右。然後,我僅拍攝ImageView和PhotoSorter的快照。 Dress Layout對於拍攝包含PhotoSorter視圖的ImageView大小的快照是必要的。不是屏幕截圖活動的大小。我會放棄這一點。 – user3164083

+0

沒有這樣的運氣,但謝謝你去。 match_parent會發生你認爲我想要的(全屏圖像)。 – user3164083

+0

試試我在編輯過的答案中所做的事情,fitXY應按照您所描述的尺寸調整圖像大小,然後裙子視圖可以包含背景並確保沒有黑色線條 –

相關問題