0

Вот код:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/view0"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
          
    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:onClick="quantity_1"
        android:text="1"
        android:textSize="30sp"
        android:textStyle="bold"
   />
  
    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        ads:srcCompat="@drawable/ba1" 
    />
</LinearLayout>

Вопрос: Можно ли в LinearLayout наложить TextView поверх ImageView?

3
  • Пожалуйста, уточните вашу конкретную проблему или приведите более подробную информацию о том, что именно вам нужно. В текущем виде сложно понять, что именно вы спрашиваете. 8 мар в 10:16
  • Зачем вам LinearLayout, если вам нужно наложить одно на другое? для этого есть другие лаяуты
    – IR42
    8 мар в 11:49
  • Если вам дан исчерпывающий ответ, отметьте его как принятый нажав на галку слева от него.
    – Andrew
    21 мар в 9:21

1 ответ 1

0

Можно сделать через FrameLayout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="100dp"
    android:layout_height="100dp">

    <TextView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_gravity="top|left"
        android:background="@android:color/holo_blue_light"
        android:gravity="center"
        android:text="First is below"/>

    <TextView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_gravity="bottom|right"
        android:background="@android:color/holo_green_light"
        android:gravity="center"
        android:text=" Last is on top"/>

</FrameLayout>

или через ConstraintLayout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="4"
    android:orientation="vertical">

    <VideoView
        android:id="@+id/videoView"
        android:layout_width="283dp"
        android:layout_height="349dp"
        android:layout_margin="24dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.509"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="24dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@mipmap/ic_launcher" />
</androidx.constraintlayout.widget.ConstraintLayout>

оба этих варианта располагают один виджет поверх другого

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.