Нарисуйте тень для двух детей в контейнере, между которыми нет места - PullRequest
1 голос
/ 04 апреля 2019

Итак, у детей есть странные тени, которые перекрывают друг друга.Есть ли способ нарисовать как одну тень для них обоих?Я имею в виду, что если они даже не находятся на одном уровне иерархии представлений.Вот чего я хочу добиться: design

screenshot Вот XML-макет

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/root"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:elevation="8dp"
    tools:context=".MainActivity">

    <View
        android:background="@android:color/white"
        android:layout_width="40dp"
        android:elevation="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_height="40dp"/>
    <View
        android:background="@android:color/white"
        android:layout_width="40dp"
        android:layout_marginTop="48dp"
        android:layout_marginStart="8dp"
        android:elevation="8dp"
        android:layout_height="40dp"/>
    <View.../>
    <View.../>
</RelativeLayout>

Ответы [ 3 ]

0 голосов
/ 04 апреля 2019
<?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout
  android:id="@+id/root"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="200dp"
  android:elevation="8dp"
  tools:context=".MainActivity">

  <View
      android:background="@android:color/white"
      android:layout_width="40dp"
      android:elevation="8dp"
      android:layout_marginStart="8dp"
      android:layout_marginTop="8dp"
      android:layout_height="40dp"/>
  <View
      android:background="@android:color/white"
      android:layout_width="40dp"
      android:layout_marginTop="68dp"
      android:layout_marginStart="8dp"
      android:elevation="8dp"
      android:layout_height="40dp"/>
  <View.../>
  <View.../>
</RelativeLayout>
0 голосов
/ 04 апреля 2019

Две вещи, которые ты можешь сделать.Вы можете использовать линейную компоновку вместо относительной компоновки или указать положение вида, например,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/root"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:elevation="8dp"
    tools:context=".MainActivity">

    <View
        android:background="@android:color/white"
        android:layout_width="40dp"
        android:elevation="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_height="40dp"/>
    <View
        android:background="@android:color/white"
        android:layout_width="40dp"
        android:layout_marginTop="48dp"
        android:layout_marginStart="8dp"
        android:elevation="8dp"
        android:layout_height="40dp"
        android:layout_toRightOf="@id/view1"/>
    <View.../>
    <View.../>
</RelativeLayout>
0 голосов
/ 04 апреля 2019

Если вы хотите, чтобы два ребенка View имели одинаковую тень, просто поместите их в одну и ту же Layout и добавьте тень на Layout

<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="8dp">

   <View
    android:background="@android:color/white"
    android:layout_width="40dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_height="40dp"/>
   <View
    android:background="@android:color/white"
    android:layout_width="40dp"
    android:layout_marginTop="48dp"
    android:layout_marginStart="8dp"
    android:layout_height="40dp"/>

</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...