Как сделать текстовое представление в виде карты в Android, используя фоновый ресурс

Это текстовое представление:

<TextView
    android:id = "@+id/text_naer_me"
    android:layout_width = "match_parent"
    android:layout_height = "wrap_content"
     android:gravity = "center"
    android:text=“Hello”
    android:background = "@drawable/rounded_white_border"
    />

Этот фоновый ресурс

<shape xmlns:android = "http://schemas.android.com/apk/res/android"
    android:shape = "rectangle">
    <stroke
        android:width = "1dp"
        android:color = "@color/light_gray" />
    <solid android:color = "@color/white" />
    <corners android:radius = "2dp" />


</shape>

текущий вид ниже

введите описание изображения здесь

ожидаемый вид ниже

введите описание изображения здесь

пожалуйста, предложите мне, как этого добиться, я хочу сделать текстовое представление в виде карты, вы можете видеть мой данный экран

просто поместите свой текст в карточку

Vivek Mishra 21.01.2019 07:06

андроид: высота = "40dp"

Manu Garg 21.01.2019 07:54
1
2
694
2
Перейти к ответу Данный вопрос помечен как решенный

Ответы 2

Use android:elevation = "20dp" and background same effect like cardview without wrap cardview

        <TextView
        android:layout_margin = "10dp"
        android:elevation = "20dp"
        android:padding = "20dp"
        android:background = "@drawable/background"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:text = "Submit"
         />
Ответ принят как подходящий

Способов много и вот они Используйте тот, который вам подходит

Create your own drawable

граница.xml

<?xml version = "1.0" encoding = "utf-8"?>
<layer-list xmlns:android = "http://schemas.android.com/apk/res/android">
    <item >
        <shape
            android:shape = "rectangle">
            <solid android:color = "@android:color/darker_gray" />
            <corners android:radius = "5dp"/>
        </shape>
    </item>
    <item android:right = "1dp" android:left = "1dp" android:bottom = "2dp">
        <shape
            android:shape = "rectangle">
            <solid android:color = "@android:color/white"/>
            <corners android:radius = "5dp"/>
        </shape>
    </item>
</layer-list>

и ваш_layout.xml

<TextView xmlns:android = "http://schemas.android.com/apk/res/android"
   xmlns:tools = "http://schemas.android.com/tools"
   android:layout_width = "match_parent"
   android:layout_height = "match_parent"
   android:orientation = "horizontal"
   android:padding = "10dp"
   android:background = "@drawable/border"
  />

You can also use use a drawable from android

android:background = "@android:drawable/toast_frame"

или:

android:background = "@android:drawable/dialog_frame"

или:

android:background = "@android:drawable/dialog_holo_light_frame"

Use a 9-patch image with a shadow and set it as the background to your Linear layout

Используйте этот веб-сайт для создания 9 патчей с тенью

http://inloop.github.io/shadow4android/

Другие вопросы по теме