线性布局无法正确显示
我已经在我的项目中创建了这个主要 XML 文件。我已经解析了 XML 文件并以线性布局动态显示。但 Linearlayout2 没有显示在我的结果中。请帮我。这是我的主要 XML 文件。我正在使用一个 XML 文件来显示我的小部件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/linearlayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:gravity="bottom"
android:text="Signature" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="30dp"
android:layout_toRightOf="@+id/button2"
android:layout_weight="1"
android:gravity="bottom"
android:text="Submit" />
</LinearLayout>
</LinearLayout>
I have created this main XML file in my project. I have parsed XML file and displayed dynamically in linear layout1. But linearlayout2 is not displaying in my result. please help me. This is my main XML file . I am using one XML file to display my widgets
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/linearlayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:gravity="bottom"
android:text="Signature" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="30dp"
android:layout_toRightOf="@+id/button2"
android:layout_weight="1"
android:gravity="bottom"
android:text="Submit" />
</LinearLayout>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
复制并粘贴此布局,通过在滚动视图中添加layout_weight和线性布局2来修改它以均匀分布屏幕。希望它能满足您的要求。
copy and paste this layout, its modified by adding layout_weight in your scroll view and linearlayout2 to equally distribute the screen. Hope it fulfills your requirements.
最好使用相对布局来解决您的问题。
Better you use relative layout for your problem.
我认为这很容易解决:
您的 ScrollView 将布局高度定义为“wrap-content”,这意味着
“孩子们可以占据所有需要的空间”。但是,在第一个孩子中您定义了高度
作为“match_parent”。这意味着“我需要尽可能多的空间”。
要解决这个问题,只需让ScrollView内的线性布局的高度
“0dip”并将layout_weight设置为“1”。
I think its easy to solve:
Your ScrollView defines the layout height to "wrap-content", it means
"childs can take all needed space". but, in the first child you define the height
as "match_parent". it means "i need most of space as i can get".
To solve the problem, simply let the height of the linearlayout within the ScrollView
"0dip" and set the layout_weight to "1".