Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.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 带百分比空白的线性布局_Android_Android Layout_Layout - Fatal编程技术网

Android 带百分比空白的线性布局

Android 带百分比空白的线性布局,android,android-layout,layout,Android,Android Layout,Layout,我正在为我的简单android应用程序设计线性布局。我想根据大小动态更改两个视图的部分(我想要的,对于从左到右的一行,前20%为空,所有内容都在其余80%内)。对于这种方法,我选择了不同视图的权重。我为这种方法创建了一个嵌套的线性布局。例如,布局层次结构如下所示 <linearLayout> //parent layout <linearLayout //child 1 layout android:layout_weight="1">

我正在为我的简单android应用程序设计线性布局。我想根据大小动态更改两个视图的部分(我想要的,对于从左到右的一行,前20%为空,所有内容都在其余80%内)。对于这种方法,我选择了不同视图的权重。我为这种方法创建了一个嵌套的线性布局。例如,布局层次结构如下所示

<linearLayout> //parent layout
   <linearLayout //child 1 layout
        android:layout_weight="1"> 
        //so that this view occupy 20% of the space regardless the width of device. I intensionally wanna keep this view empty. 
   </linearLayout>
   <linearLayout //child 2 layout
         android:layout_weight="4">
          //so that this view occupy 80% of the space regardless the width of device. and 
          //inside this view I have whatever view I wanna add on it. 
      <EditText>
      <ImageView>
   </linearLayout>
</linearLayout>
//父布局
//因此,无论设备的宽度如何,此视图都会占用20%的空间。我想让这个观点保持空白。
//因此,无论设备的宽度如何,该视图都占据了80%的空间。及
//在这个视图中,我有我想添加的任何视图。
通过这种方法,Android Studio中的Lint会告诉我以下警告:

  • 这是一个嵌套布局。布局权重要求小部件测量两次。当具有非零权重的线性布局嵌套在另一个具有非零权重的线性布局中时,测量数量将以指数方式增加

  • 子1布局无效:此
    线性布局
    视图无效(无子视图,无
    背景
    ,无
    id
    ,无
    样式

  • 有人能告诉我要使用的正确布局,以便根据设备的大小动态更改布局吗?如何正确设置线性布局案例的空白空间

    看一看


    注意:您需要使用它。

    这是一种使用权重的可能解决方案:

    <LinearLayout
        android:layout_width="match_parent"
        android:gravity="end"
        android:weightSum="1">
    
        <!-- Your content here: -->
        <View
            android:layout_width="0dp"
            android:layout_weight="0.8"
            android:layout_gravity="end" />
    
    </LinearLayout>
    

    这正是我想要的。谢谢