Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android RelativeLayout不';行不通_Android_Android Relativelayout - Fatal编程技术网

Android RelativeLayout不';行不通

Android RelativeLayout不';行不通,android,android-relativelayout,Android,Android Relativelayout,我的RelativeLayout有问题 我将6个视图放在一起,它可以正常工作 我遇到的问题是编辑文本。当我将它们的宽度设置为wrap\u content时,它们太小了 当我将它们设置为match\u parent时,它们采用整个宽度(它们覆盖了其他视图),而不是调整到它们旁边的视图的边缘 所以我的问题是,如何在不给它们静态宽度的情况下使它们合适 这是我的密码: <RelativeLayout android:id="@+id/relativelayout1" android

我的
RelativeLayout
有问题

我将6个
视图
放在一起,它可以正常工作

我遇到的问题是
编辑文本
。当我将它们的宽度设置为
wrap\u content
时,它们太小了

当我将它们设置为
match\u parent
时,它们采用整个宽度(它们覆盖了其他
视图
),而不是调整到它们旁边的
视图的边缘

所以我的问题是,如何在不给它们静态宽度的情况下使它们合适

这是我的密码:

<RelativeLayout
    android:id="@+id/relativelayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/tv1"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="text 1" />

    <EditText
        android:id="@+id/et1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv1"
        android:singleLine="true" />

    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/et1"
        android:text="text 2" />

    <EditText
        android:id="@+id/et2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv2"
        android:singleLine="true" />

    <TextView
        android:id="@+id/tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/et2"
        android:text="text 3" />

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/tv3" />

</RelativeLayout>

请尝试以下代码

如果你想让盒子的大小有点不同,你需要应用静态大小或者稍微调整一下重量,以获得你想要的合适空间

不过,我建议实际更改一下布局。把它们放在同一条线上似乎有点混乱。除非这是横向模式。那就可以了



布局的结果图片:


请尝试以下代码

如果你想让盒子的大小有点不同,你需要应用静态大小或者稍微调整一下重量,以获得你想要的合适空间

不过,我建议实际更改一下布局。把它们放在同一条线上似乎有点混乱。除非这是横向模式。那就可以了



布局的结果图片:


对于相对布局,您需要满意的包装内容或静态尺寸。
如果我理解得很好,您希望编辑文本填充屏幕剩余的宽度。 您必须使用线性布局和
android:layou-weight
属性-:


对于相对布局,您需要满意的包装内容或静态尺寸。
如果我理解得很好,您希望编辑文本填充屏幕剩余的宽度。 您必须使用线性布局和
android:layou-weight
属性-:



我已经尝试使用布局权重进行线性布局。我的表格布局也有同样的问题。当输入文本并到达编辑文本的右边缘时,它们会不断拉伸并将其他视图推离屏幕。试试这个,让我看看它是如何进行的。复制并粘贴到布局文件中。这对我有用,也应该对你有用。我发布了结果布局的屏幕截图。答案按用户排序。对于每个人来说,它们可能并不总是以相同的顺序出现。你只需要告诉人们看一个特定的解决方案。我已经尝试了线性布局和布局权重。我的表格布局也有同样的问题。当输入文本并到达编辑文本的右边缘时,它们会不断拉伸并将其他视图推离屏幕。试试这个,让我看看它是如何进行的。复制并粘贴到布局文件中。这对我有用,也应该对你有用。我发布了结果布局的屏幕截图。答案按用户排序。对于每个人来说,它们可能并不总是以相同的顺序出现。您只需要告诉人们查看特定的解决方案。您可以做的一件事是将它们包装在
LinearLayouts
中,然后将其宽度设置为
match\u parent
。这样,无论它们包含多少文本,它们都将始终具有相同的宽度。然后,只需将
线性布局的宽度
权重
平衡即可。您还需要设置
editText
以允许文本滚动。您的意思是将每个视图放在它自己的线性布局中吗D我知道它是有效的(我以前也这么做过),但它需要很多性能。实际上,我想用一种更优雅的方式来实现这一点。“你是说把每个视图放在它自己的线性布局中?”是的。你说“需要很多表现”是什么意思?你是说它很慢吗?如果是这样,您是在模拟器(v.slow)上测试还是在真实设备上测试?同意,嵌套布局太深不是一个很好的方法,但我有一些是2或3层,在真实设备上没有明显的屏幕延迟。当然,它可能并不优雅,但如果它能让我的布局完全符合我的要求(包括在不同的屏幕dpi/大小上精确调整),我很乐意这样做。你可以做的一件事是将它们包装在
线性布局中,然后将它们的宽度设置为
匹配\u parent
。这样,无论它们包含多少文本,它们都将始终具有相同的宽度。然后,只需将
线性布局的宽度
权重
平衡即可。您还需要设置
editText
以允许文本滚动。您的意思是将每个视图放在它自己的线性布局中吗D我知道它是有效的(我以前也这么做过),但它需要很多性能。实际上,我想用一种更优雅的方式来实现这一点。“你是说把每个视图放在它自己的线性布局中?”是的。你说“需要很多表现”是什么意思?你是说它很慢吗?如果是这样,您是在模拟器(v.slow)上测试还是在真实设备上测试?同意,嵌套布局太深不是一个很好的方法,但我有一些是2或3层,在真实设备上没有明显的屏幕延迟。当然,它可能并不优雅,但如果它能够准确地获得我想要的布局(包括在不同的屏幕dpi/大小上进行精确调整),我很乐意这样做。“如果我理解得很好,您希望编辑文本填充屏幕剩余的宽度。”是的,这正是我想要的。就像我说的,我已经用LinearLayout试过了,但是当我打字的时候,编辑文本一直在拉伸,并且到达了正确的边缘。如果你打字,有没有办法防止他们拉伸?对不起,查尔斯,我读得不好。我知道你没有给每个视图赋予布局权重,只给了两个
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativelayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/tv1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="text 1" />

    <EditText
        android:id="@+id/et1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true" />

    <TextView
        android:id="@+id/tv2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="text 2" />

    <EditText
        android:id="@+id/et2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true" />

    <TextView
        android:id="@+id/tv3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="text 3" />

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_toRightOf="@+id/tv3" />

</LinearLayout>
<LinearLayout
        android:id="@+id/ll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation:"horizontal">
        <TextView
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:text="text 1" />

        <EditText
        android:id="@+id/et1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true"/>

        <EditText
        android:id="@+id/et2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="true" />

        <TextView
        android:id="@+id/tv3"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="text 3" />

        <Spinner
        android:id="@+id/spinner1"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true" />

</LinearLayout>