添加视图的RelativeLayout改变其大小 [英] Adding a View to RelativeLayout changes its size

查看:149
本文介绍了添加视图的RelativeLayout改变其大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为着装与WRAP_CONTENT的的LayoutParams RelativeLayout的。所有这一切都在它里面是一个ImageView的,所以它的大小作为ImageView的相同。当我增加一个着眼于RelativeLayout的OnCreate中中,就像这样:

I have a RelativeLayout called "Dress" with LayoutParams of WRAP_CONTENT. All that is inside it is an ImageView, so it is the same size as the ImageView. When I add one more view to the RelativeLayout in OnCreate, like this:

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,基本上整个活动,减去动作条。

The RelativeLayout called Dress changes size, to take up the whole RootView, basically the whole activity, minus the actionbar.

我把礼服布局的屏幕截图。所以当photoSorter在RootLayout(不连衣裙布局)是这样的:

I take a screenshot of the Dress Layout. So when photoSorter is in the RootLayout (NOT the Dress Layout) like this:

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

布局连衣裙是正确的大小和我得到这个截图这就是我想要的:

Layout Dress is correct size and I get this screenshot which is what I want:

但我需要PhotoSorter在着装上的布局,这样我可以包括在我的截图,而不是有黑条。当我photoSortr添加到连衣裙布局是这样的:

But I need PhotoSorter in the Dress Layout so that I can include it in my screenshot and not have the black strips. When I add the photoSortr to the Dress Layout like this:

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

这使得连衣裙布局占据整个屏幕,这样的着装布局的截图如下:

It makes the Dress Layout take up the whole screen so the screenshot of the Dress Layout looks like this:

下面是我的code采取截图:

Here is my code to take a screenshot:

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

下面是我的XML的活动:

Here is my XML for the activity:

<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,它把衣服布局占据整个活性。因此,添加任何的礼服布局使它大。

Also When I added com.edmodo.cropper.CropImageView to the DressLayout, it made the Dress Layout take up the whole activity as well. So adding anything to the Dress Layout is making it bigger.

我怎么可以添加photoSorter到着装布局未做连衣裙布局占据整个活动的规模?

How can I add photoSorter to the Dress Layout without making Dress Layout take up the whole activity size?

感谢。

推荐答案

我在尝试XML的东西出来管理。关键是要对准连衣裙imageViewDress,我可以对齐的另一侧,以更彻底,不只是底部。

I managed by trying things out in XML. The key is to align Dress with imageViewDress, I could align the other sides to be more thorough, not just bottom.

<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的截图。

This XML, then add photoSorter to Dress programmatically, then take a screenshot of DressBig.

这篇关于添加视图的RelativeLayout改变其大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆