【问题标题】:Android - Stack XML Layouts ontop of each otherAndroid - 将 XML 布局堆叠在一起
【发布时间】:2015-07-28 20:31:17
【问题描述】:

我的名字是库珀。对Java相当陌生(一个月左右)

如果你在哪里看 instagram,他们的图像堆叠在图像上,带有 cmets 等。

看起来 XML 布局只是被复制并粘贴在彼此之上。

这就是他们正在做的事情吗? 我该怎么做?

【问题讨论】:

    标签: java android


    【解决方案1】:

    FrameLayout 和RelativeLayout 让您可以将视图堆叠在一起,z 索引是按照它们在代码中添加或在xml 中写入的顺序。 布局基本上是带有规则的 ViewGroup 的扩展,如果您想在布局中包含另一个布局,请查看 <include><merge> 标签: http://developer.android.com/training/improving-layouts/reusing-layouts.html

    【讨论】:

    • 现在我怎么能拥有例如:布局 1 以编程方式包含布局 1?
    • 任何布局都可以使用 View.inflate 进行膨胀,并检查有关将新视图添加到 FrameLayout 的问题,例如:stackoverflow.com/a/8931551/348378
    【解决方案2】:

    这是一个使用FrameLayout 和一些TextViews 的示例。此FrameLayout 中的所有视图都将出现在 (0,0) 坐标处,但在子视图的 android:layout_marginLeft/android:layout_marginStartandroid:layout_marginTop 属性的维度中发现偏移量

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    
        <TextView
            android:text="11111111"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="6dp"
            android:layout_marginTop="6dp"
            android:layout_marginStart="6dp" />
    
    
        <TextView
            android:text="2222222"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="12dp"
            android:layout_marginTop="12dp"
            android:layout_marginStart="12dp" />
    
        <TextView
            android:text="3333333"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="18dp"
            android:layout_marginTop="18dp"
            android:layout_marginStart="18dp" />
    
    </FrameLayout>
    

    它是什么样子的:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-15
      • 1970-01-01
      • 1970-01-01
      • 2010-12-26
      • 1970-01-01
      • 1970-01-01
      • 2021-12-23
      • 1970-01-01
      相关资源
      最近更新 更多