[英]How to set the width of LinearLayout inside RelativeLayout to be independent of screen resolution?
I am a newbie in Android-programing and currently I'm building my first application. 我是Android编程的新手,目前正在构建我的第一个应用程序。 I have a LinearLayout (with several imageviews), which is situated inside of basic RelativeLayout.
我有一个LinearLayout(带有几个imageviews),它位于基本的RelativeLayout内部。 The xml width and heigth settings of LinearLayout are as follows:
LinearLayout的xml宽度和高度设置如下:
android:layout_width="135dp"
android:layout_height="match_parent"
The settings of imageviews inside LinearLayout look like this: LinearLayout中的imageviews设置如下所示:
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="125dp"
android:layout_weight="3"
.....
When I start my application on small screens, it looks normal, but when the screen is big, all the pictures become very narrow (the width of LinearLayout inside RelativeLayout stays the same on small and big screen). 当我在小屏幕上启动应用程序时,它看起来很正常,但是当屏幕很大时,所有图片都变得非常狭窄(RelativeLayout内部的LinearLayout的宽度在大屏幕和大屏幕上都保持不变)。 I tried to set it in percentage, but that is not allowed.
我尝试将其设置为百分比,但不允许这样做。 So I ask you: how can I set the width of LinearLayout to be like 25-30% of the width of parent RelativeLayout(to make my images look pretty on any device).
所以我问你:如何将LinearLayout的宽度设置为父RelativeLayout宽度的25%至30%(以使我的图像在任何设备上看起来都很漂亮)。
I know that there is a layout_weight attribute, but it doesn't seem to work with layouts inside another layouts (or maybe I have no idea what is correct or what is not). 我知道有一个layout_weight属性,但是它似乎不适用于其他布局中的布局(或者也许我不知道什么是正确的,什么是不正确的)。
As I know, you cant take parent layout percantage to child layout. 据我所知,您不能将父布局的布局带入子布局。
Linearlayout add elements to as columns or as row.
Linearlayout将元素添加为列或行。
Relative Layout 相对布局
A Layout where the positions of the children can be described in relation to each other or to the parent.
可以相对于彼此或相对于父项描述子项位置的布局。
Why do you use linearlayout inside relative layout? 为什么在相对布局中使用linearlayout? In linearlayout you cant design your layout elements puting element with mouse,But in relativelayout you can.
在linearlayout中,您无法使用鼠标设计布局元素放置元素,但在relativelayout中,则可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.