的LinearLayout在正方形正方形、LinearLayout

由网友(梦想不只是梦与想)分享简介:是有可能有与高度相等的LinearLayout一个内部的LinearLayout和动态宽度?我不想指定的值,只是高度是可能的宽度相同的尺寸。is it possible to have a LinearLayout inside a LinearLayout with equal height and width d...

是有可能有与高度相等的LinearLayout一个内部的LinearLayout和动态宽度?我不想指定的值,只是高度是可能的宽度相同的尺寸。

is it possible to have a LinearLayout inside a LinearLayout with equal height and width dynamically? i don't want to specify the values, just that the height is the same size of the possible width.

THX

推荐答案

我有同样的问题,我无法找到一个方法来解决这个问题只使用XML。所以我写了自定义布局,并从XML参考吧。

I have the same problem and i couldn't find a way to solve this using only xml. So i wrote custom layout and reference it from xml.

public class SquareLayout extends LinearLayout {

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, widthMeasureSpec);
            // or you can use this if you want the square to use height as it basis
            // super.onMeasure(heightMeasureSpec, heightMeasureSpec); 
    }
}

和引用它的XML像这样

and reference it in xml like this

<your.package.SqureLayout .....
</your.package.SquareLayout>

如果有最简单的解决方案,我会很高兴知道这一点。

If there is easiest solution i'll be glad to know it.

阅读全文

相关推荐

最新文章