android布局屏幕一半,Android:2个相对布局划分为一半屏幕(Android: 2 relative layout divided in half screen)...

Android:2个相对布局划分为一半屏幕(Android: 2 relative layout divided in half screen)

我多次尝试绘制2个水平对齐的相对布局,并将其分为两半。

5d10b5decd6987f6faac4a77eb54a0a4.png

我用油漆设计图像来更好地解释我的意思。

任何建议?

I tried many times to draw 2 Relative layout aligned horizontally and divided in half screen.

5d10b5decd6987f6faac4a77eb54a0a4.png

I design the image with paint to explain a bit better what i mean.

Any suggestion?

原文:https://stackoverflow.com/questions/19983335

更新时间:2019-10-27 04:02

最满意答案

您可以将这2个RelativeLayouts放置在水平方向的LinearLayout内,然后使用两个RelativeLayouts的权重 。 这会将LinearLayout分成2等份。

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:baselineAligned="false">

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1">

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1">

You can put these 2 RelativeLayouts inside a LinearLayout with horizontal orientation, then use the weight for both RelativeLayouts. This will divide the LinearLayout in 2 equal parts.

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:baselineAligned="false">

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1">

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1">

2013-11-14

相关问答

您可以将这2个RelativeLayouts放置在水平方向的LinearLayout内,然后使用两个RelativeLayouts的权重 。 这会将LinearLayout分成2等份。

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

android:baselineAligne

...

做这个 <?xml version="1.0" encoding="utf-8"?>

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:we

...

public void surfaceCreated(SurfaceHolder holder)

{

// The Surface has been created, acquire the camera and tell it where to draw.

mCamera = Camera.open();

Parameters params = mCamera.getParameters();

if (this.getResources().getConfiguration().orient

...

这可以通过在布局上使用两个小部件来完成:在两个小部件(Button和另一个小部件)上使用LinearLayout并设置layout_width="fill_parent" ,并将layout_weight设置为相同的值。 并且LinearLayout将平分两个小部件之间的宽度,并且您的按钮将占据屏幕的一半。

xmlns:tools="http://sch

...

使用Parent作为LinearLayout并使用weightSum和weight属性 样品

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:ori

...

“使用上面的XML文件后,我无法在Android屏幕上正确看到我的标签和两个文本框,我的XML文件中是否有任何遗漏?” 看来,你可能已经弄乱了你的LinearLayout标签。 看看这是否更接近您所寻找的: <?xml version="1.0" encoding="utf-8"?>

android:layout_width="match_par

...

我通过删除解决了这个问题 super.init();

来自droidgap活动的onCreate方法。 奇怪的是,我读到了你需要这个以便1.1工作的地方。 I resolved this by removing super.init();

from the droidgap activity's onCreate method. Odd, I read somewhere you needed this for 1.1 to work.

对不起Urban,给了你一个屁股踩它 - 我以前看过这个,我可以通过编程方式限制地图大小的唯一方法,但是,我已经用这种类型的布局完成了它: <?xml version="1.0" encoding="utf-8"?>

android:layout_width="fill_parent"

android:layout_height="fill_pare

...

首先,您可以使用名为DisplayMetrics的android.Util类获取高度和宽度: DisplayMetrics displayMetrics = new DisplayMetrics();

然后将当前显示信息插入声明的DisplayMetrics : getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

现在,您可以使用以下方法获取屏幕的高度和宽度: displayMetri

...

您可以在XML中使用以下内容进行垂直分割屏幕:这里我们使用权重和权重属性。 您可以调整重量属性以获得半个或四分之一等所需的结果。

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_p

...