gpt4 book ai didi

android - 在线性布局中嵌套相对布局

转载 作者:行者123 更新时间:2023-11-29 14:57:06 29 4
gpt4 key购买 nike

我的 layout.xml 中有以下代码。

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent">

<EditText android:hint="@string/feed_url"
android:id="@+id/feedUrl" android:textSize="14dp" android:inputType="textUri"
android:layout_marginRight="45dp" android:layout_height="wrap_content" android:layout_width="fill_parent">
</EditText>

<Button android:id="@+id/getGraph"
android:text="@string/get"
android:layout_toRightOf="@id/feedUrl"
android:layout_alignParentRight="true"
android:layout_height="wrap_content" android:width="45dp" android:layout_width="wrap_content">
</Button>

</RelativeLayout>

<WebView android:id="@+id/wv1" android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>

在 eclipse 插件布局创建器中,EditText 和按钮正确显示。 (见下面的截图)

alt text

但在设备和模拟器上,按钮并没有被隐藏。 (见下面的截图)

alt text

知道为什么按钮在设备中隐藏了吗?

最佳答案

尝试对您的代码进行以下更改。您必须首先定义按钮,因为它是固定宽度的,然后放置 EditText 以填充其余空间,放置在按钮的左侧。还必须首先定义按钮(即在 Android 2.2 之前)。

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent">

<Button
android:id="@+id/getGraph"
android:text="@string/get"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<EditText
android:hint="@string/feed_url"
android:id="@+id/feedUrl"
android:textSize="14dp"
android:inputType="textUri"
android:layout_marginRight="45dp"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toLeftOf="@id/getGraph"
/>
</RelativeLayout>

关于android - 在线性布局中嵌套相对布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3941723/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com