简体   繁体   English

如何设置RelativeLayout内部的LinearLayout的宽度与屏幕分辨率无关?

[英]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将元素添加为列或行。

linearlayout api 线性布局API

Relative Layout 相对布局

A Layout where the positions of the children can be described in relation to each other or to the parent. 可以相对于彼此或相对于父项描述子项位置的布局。

Relative Layout api 相对布局API

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.

相关问题 如何将RelativeLayout的宽度设置为屏幕宽度? - How I set the width of RelativeLayout to screen width? 设置relativelayout的宽度为屏幕宽度的1/3? - Set the width of relativelayout 1/3 the width of the screen? 在 relativelayout 中动态设置 LinearLayout 的高度/宽度 - dynamically set LinearLayout height/width in relativelayout 屏幕底部的ScrollView和RelativeLayout中的LinearLayout - LinearLayout at bottom of the screen inside a ScrollView and RelativeLayout 如何以编程方式调整RelativeLayout中LinearLayout的宽度? - How to adapt the width of a LinearLayout in a RelativeLayout programmatically? RelativeLayout内LinearLayout内按钮的非相等宽度 - Non equal width of button inside LinearLayout inside RelativeLayout 如何在Android中的Relativelayout内部放置一个Linearlayout - How to place a Linearlayout at bottom inside a Relativelayout in android 如何在coordinatorLayout内的RelativeLayout底部对齐LinearLayout - how to align LinearLayout at the bottom of RelativeLayout inside coordinatorLayout 如何以编程方式(动态)将LinearLayout放在RelativeLayout内部? - How to programmatically (dynamically) center a LinearLayout inside a RelativeLayout? 如何在其父级RelativeLayout的中心设置LinearLayout? - How to set LinearLayout at center of it's parent RelativeLayout?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM