我有一个名为“Dress”的相对布局,其 LayoutParams 为 WRAP_CONTENT。它里面的所有内容都是一个ImageView,因此它的大小与ImageView相同。当我在 OnCreate 中向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);
称为 Dress 的相对布局会更改大小,以占据整个 RootView,基本上是整个 Activity,减去操作栏。
我截取了服装布局的屏幕截图。因此,当 photoSorter 在 RootLayout (不是 Dress Layout)中时,如下所示:
photoSorter = new MultitouchImagesView(this.getApplicationContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
addContentView(photoSorter, params);
布局连衣裙尺寸正确,我得到的屏幕截图正是我想要的:
但我需要在 Dress Layout 中使用 PhotoSorter,这样我就可以将它包含在我的屏幕截图中并且没有黑条。当我将 photoSortr 添加到 Dress Layout 时,如下所示:
photoSorter = new MultitouchImagesView(this.getApplicationContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
((ViewGroup) findViewById(id.Dress)).addView(photoSorter, params);
它使 Dress Layout 占据整个屏幕,因此 Dress Layout 的屏幕截图如下所示:
这是我的截图代码:
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 时,它使得 DressLayout 也占据了整个活动。因此,在服装布局中添加任何内容都会使其变得更大。
如何将 photoSorter 添加到 Dress Layout 而不使 Dress Layout 占用整个活动大小?
Thanks.