Java 如何在另一个布局中嵌入布局?

Java 如何在另一个布局中嵌入布局?,java,android,xml,layout,Java,Android,Xml,Layout,我想要一个类似下图的布局,其中(2)是一个线性布局,(1)是任何可以使这成为可能的布局。 例如,想象(2)是一个按钮配置,(1)是一些不同大小的文本,需要四处移动(2) 似乎人们误解了我的问题,即使在图像演示中,(2)也不在(1)之上!!!让我添加一个更详细的图像,如下所示: 很简单,你做过约束布局吗?试试这个 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas

我想要一个类似下图的布局,其中(2)是一个线性布局,(1)是任何可以使这成为可能的布局。 例如,想象(2)是一个按钮配置,(1)是一些不同大小的文本,需要四处移动(2)

似乎人们误解了我的问题,即使在图像演示中,(2)也不在(1)之上!!!让我添加一个更详细的图像,如下所示:


很简单,你做过约束布局吗?试试这个

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

   <androidx.constraintlayout.widget.ConstraintLayout
       android:layout_width="match_parent"
       android:layout_height="250dp">

      <ImageView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:src="@mipmap/ic_launcher"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent" />


      <ImageView
          android:layout_width="80dp"
          android:layout_height="80dp"
          android:src="@mipmap/ic_launcher"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="1.0"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="1.0" />


   </androidx.constraintlayout.widget.ConstraintLayout>



</LinearLayout>

请尝试使用此代码(将此代码粘贴到xml布局文件中)并获得结果。
注意:您必须根据此处给出的定义约束。

我建议您使用
include
。请注意,如果将
android:id..
包含在
标记中,它将覆盖包含的布局中定义的任何id。例如:

<include
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:id="@+id/some_id_if_needed"
   layout="@layout/yourlayout" />

根本不起作用。我猜你不明白我的问题。我曾经使用过约束布局,但你会怎么做?据我所知,没有任何相关的选择。根本不是我问的我的朋友!我没有说(2)需要在(1)之上!!这也可以通过一个简单的relativelayout来实现。假设您的第一个图像是文本,那么您的第二个图像不应该位于文本之上。但文字应该环绕图像。你的问题是“如何将文字环绕图像”?
<LinearLayout
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:id="@+id/some_other_id">
   <Button
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:id="@+id/button1" />
 </LinearLayout>
View includedLayout = findViewById(R.id.some_id_if_needed);
Button insideTheIncludedLayout = (Button)includedLayout.findViewById(R.id.button1);