线性布局无法正确显示

发布于 2024-12-25 23:24:50 字数 2462 浏览 4 评论 0原文

我已经在我的项目中创建了这个主要 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

巴黎盛开的樱花 2025-01-01 23:24:50

复制并粘贴此布局,通过在滚动视图中添加layout_weight和线性布局2来修改它以均匀分布屏幕。希望它能满足您的要求。

<?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"
                android:layout_weight="1" >
                <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"
                android:layout_weight="1" >
                <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>

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.

<?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"
                android:layout_weight="1" >
                <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"
                android:layout_weight="1" >
                <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>
煮茶煮酒煮时光 2025-01-01 23:24:50

最好使用相对布局来解决您的问题。

Better you use relative layout for your problem.

红ご颜醉 2025-01-01 23:24:50

我认为这很容易解决:

您的 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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文