[英]Add View to RelativeLayout in OnCreate()
編輯請查看此問題的底部,其中顯示編輯 。 因為我通過將<com.edmodo.cropper.CropImageView
從內部布局移動到根布局來解決了這個問題。 但是現在我仍然需要將添加的子視圖添加到名為“Dress”的內部布局中,以便在屏幕截圖中顯示它們。 謝謝。
我拍了一張RelativeLayout的截圖。 屏幕截圖必須僅顯示RelativeLayout內部的ImageView的大小。 我無法截取ImageView本身的截圖是因為我有其他的子視圖被添加到需要在屏幕截圖中的ImageView之上。
<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=".DressingRoomActivity" >
<RelativeLayout
android:id="@+id/Dress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent" >
<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" />
<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>
</RelativeLayout>
我的代碼采取截圖:
public Bitmap takeScreenshot() {
View v = findViewById(R.id.Dress);
v.setDrawingCacheEnabled(true);
return v.getDrawingCache();
}
編輯:我沒有在截圖中獲得子視圖。 我曾經截取活動的RootView截圖來獲取它們,但我不想要動作欄,所以我需要截取內部relativeLayout的截圖。 但正如您所看到的,我將子視圖添加到Rootview中,如下所示:
photoSorter = new MultitouchImagesView(this.getApplicationContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
addContentView(photoSorter, params);
我可以更改它以將它們添加到名為“Dress”的RelativeLayout嗎?
謝謝
從ImageView中刪除padding屬性並將ScalType更改為android:scaleType="fitXY"
<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:scaleType="fitXY" />
android:padding =“10dp”從你的xml imageview代碼中刪除這一行......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.