这是基本的XML文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/white"
>
<!--top part-->
<include layout="@layout/top" android:layout_width="fill_parent"
android:layout_height="0dp" android:layout_weight="1"/>
<!--content area-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:background="#ff6600"
>
</LinearLayout>
<!--bottom part-->
<include layout="@layout/bottom" android:layout_width="fill_parent"
android:layout_height="0dp" android:layout_weight="1"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
当我在模拟器中加载它时,它看起来像在下面的图像.

我究竟做错了什么?
编辑
这是顶部和底部的XML.基本也是.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/bottom_image"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:adjustViewBounds="true"
android:src="@drawable/bottom"
/>
</LinearLayout>
-----------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/top_image"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:adjustViewBounds="true"
android:src="@drawable/top"
/>
Run Code Online (Sandbox Code Playgroud)
我必须建立如下图所示的布局.主要任务是使文本居中.

我使用这个xml来实现布局.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="@+id/author"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/author">
</LinearLayout>
<LinearLayout
android:id="@+id/footer_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<LinearLayout
android:id="@+id/menu_layout"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="@drawable/nav_overlay"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="@+id/previous"
android:layout_width="45dp"
android:layout_height="45dp"
android:background="@drawable/button" />
</LinearLayout>
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/admob_id"
ads:loadAdOnCreate="true" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
但它工作不正确.
我需要中心TextView android:id="@+id/author"内LinearLayout android:id="@+id/ll".但它以父母为中心RelativeLayout android:id="@+id/main_layout".
我用的android:layout_height="fill_parent"是LinearLayout android:id="@+id/ll".
我的布局如何填充不是父级而是仅剩余空间?
如果有人遇到类似的问题,请举例说明其实施情况.
编辑:现在我有错误的居中文本,如下图所示.

此时,我认为最好的解决方案是使用android:layout_weight.
但是,当广告未显示时 …
所以我正在为我的应用程序设计一个设计,我需要在imageview下面直接放置一个图像按钮.但是由于我的imageview周围有一个带阴影的边框,我需要隐藏(向上移动)可能在我的imageview后面10个像素的图像按钮.这是我想要的快速绘图.

我希望这是有道理的.我一直在搞乱各种不同的安排,但我不能得到我想要的东西.任何帮助将不胜感激.
我有这样的布局.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
....>
<LinearLayout
android:id="@+id/box1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
...............
..............
</LinearLayout>
<LinearLayout
android:id="@+id/box2"
android:background="#c0000000"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
.............
.............
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
Box2显示在Box1上方,由于Box2的半透明颜色,Box1部分可见.现在我想通过box2消耗掉所有的触摸事件,这样Box2中的Buttons和EditTexts就不起作用了.如何通过java代码完成?
我有一个Linearlayout,我想让它可以滚动而不使用ScrollView.可能吗.任何建议将不胜感激.下面是详细信息:如果我使用ScrollView包装LinearLayout,它可以,但是当我在LinearLayout中使用ListView时(因为它是我的客户端要求),它说不要在ScrollView中使用ListView.我必须使用ListView显示50个产品列表,我必须将此ListView放在LinearLayout中,同时整个布局将是可滚动的.可能吗.这是骨架:
<LinearLayout>
<RelativeLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<TextView>
</LinearLayout>
<LinearLayout>
<ListView>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
重要说明:请参阅ListView我要添加50列表项的位置.那么如何才能使这个整体LinearLayout可滚动.
我正在设计如下布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/messageText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Some really long text asd asd asd asd asd asd asd asd asd asd asd![enter image description here][1]" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12:45 PM" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
它提供了如上所述的UI ...

哪个是我需要的完美.由于方向是水平的,因此不会将Button推离屏幕,因此长文本正在被正确包裹.按钮也没有伸展.
但如果文字很小.看起来像这样

我想要的是按钮应该像这样对齐到文本的左端

我知道,因为我把布局权重设为1.
在为按钮提供所需空间后,它会占用整个区域.
如果我不这样做.并使宽度成为包装内容.它适用于短文本.但随着文本的增长.
它将按钮推离屏幕.
那就是问题所在.希望我让我的问题足够描述.但当然很长时间阅读.痛苦当然.但是真的很高兴知道任何指针.
我也不愿意使用相对布局.
任何帮助将不胜感激.
谢谢
我试图禁用线性布局内的所有字段.线性布局中有许多edittext和textview.但是,我只是试图禁用edittext.我能够禁用所有孩子,但我希望能够禁用编辑文本.有没有办法做到这一点?
我有一个非常简单的RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frag"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@+id/listApplications"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<!-- AD SERVER -->
<ImageView
android:id="@+id/ad_server_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="0dp"
android:contentDescription="@string/ad_banner_image_description"
android:gravity="bottom|center_horizontal"
android:paddingBottom="0dp" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
ImageView与其父级(RelativeLayout)的底部对齐,我将填充/边距设置为0,但我在图像的顶部和底部得到一个白色的"边框"(请参阅红色标记):

谢谢 !
我有一个LinearLayout已经包含多个元素.我想以编程方式添加底部边距.
我在适配器代码中添加以下代码段.
两者都不起作用.
View linearLayout = convertView.findViewById(R.id.spinnerL);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)linearLayout.getLayoutParams();
params.setMargins(0, 0, 0, 10);
linearLayout.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud)
这个甚至删除了我的元素:
View linearLayout = convertView.findViewById(R.id.spinnerL);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(30, 20, 30, 10);
linearLayout.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?如何在运行时添加边距?
我有一个场景,当视图被回收时,布局是不正确的.我的行项目布局如下(注意wrap_contentLinearLayout宽度weight,,和ellipsize):
<LinearLayout
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/text1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="middle"
android:singleLine="true"
tools:text="Ann really freaking long last name Droid"
/>
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
row1 | 1-short-text | 2-text | 3-more-text
----------------------------------------------------
row2 | 1-short-text | 2-text | 3-more-text
----------------------------------------------------
row3 | 1-long-ellipsiz...text | 2-text | 3-more-text
----------------------------------------------------
row4 | 1-tiny | 2-text-longer | 3-more-text-blah
----------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
row1 | 1-...et | 2-text | 3-more-text …Run Code Online (Sandbox Code Playgroud)