方形的LinearLayout

Maf*_*ffo 7 android android-linearlayout

是否有可能在LinearLayout内部具有相同高度和宽度的LinearLayout动态?我不想指定值,只是高度与可能的宽度相同.

谢谢

Moj*_*sin 16

我有同样的问题,我找不到使用xml解决这个问题的方法.所以我写了自定义布局并从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); 
    }
}
Run Code Online (Sandbox Code Playgroud)

并像这样在xml中引用它

<your.package.SqureLayout .....
</your.package.SquareLayout>
Run Code Online (Sandbox Code Playgroud)

如果有最简单的解决方案,我会很高兴知道它.