繁体   English   中英

RelativeLayout具有相同的宽度和高度

[英]RelativeLayout to have the same width and height

我有一张照片列表,每张照片中都有一些文字。 我希望每张照片水平填满屏幕,并希望高度与宽度相同

试图完成类似的事情

<RelativeLayout
  android:layout_width="match_parent"
  android:layout_height="self.width"
...

我该怎么做呢?

由于我将使用recycleview,因此我可以在运行时编辑高度。

以编程方式找到布局的宽度,然后将该值设置为布局的高度。

//get Width
int width=layout.getWidth();

//set height
layout.getLayoutParams().height=width;

XML不是动态的。 屏幕测量必须在onCreate期间用Java完成。

 Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point(); display.getSize(size);
    int width=size.x; int height=size.y;

LinearLayout.LayoutParams params= new LinearLayout.LayoutParams(width,width);
yourView.setLayoutParams(params);
should be like this,if you want height for full screen use match_parent also

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"

/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM