如何在 Android 中使用带有边框和彩色区域的背景 [英] How to use a background with rims and colored areas in Android

查看:34
本文介绍了如何在 Android 中使用带有边框和彩色区域的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个布局,我可以在其中放置其他布局(例如受限布局),并且这些布局应该有边框和彩色区域.所以我想我必须改变背景,但我不知道如何.这是我当前片段的屏幕截图,我强调了我想添加的内容:

I would like to have a layout in which I put other layouts (e.g. constrained layout) and those layouts should have rims and colored areas. So I guess I have to change the background but I do not know how. Here is a screenshot of my current fragment and I highlited the things that I would like to add:

基本上它应该看起来有点类似于 所需的布局.

Basically it should look somehow similar to Desired layout.

这是我拥有的 XML 布局文件

Here is the XML-layout file that I have

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_marginTop="@dimen/_28sdp"
        android:layout_width="@dimen/_220sdp"
        android:layout_height="@dimen/_240sdp"
        android:orientation="vertical"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.93"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"


        app:layout_constraintVertical_bias="0.75">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/_30sdp"
            android:orientation="horizontal"></LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/_190sdp"
            android:orientation="vertical"></LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/_20sdp"
            android:orientation="horizontal"></LinearLayout>
    </LinearLayout>

    <Button
        android:id="@+id/navigation_button_language"
        android:layout_width="@dimen/_31sdp"
        android:layout_height="@dimen/_31sdp"
        android:background="@drawable/navigation_buttom"
        android:text="Dummy"
        android:textAllCaps="false"
        android:textColor="#121212"
        android:textSize="@dimen/_9ssp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.95"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.02" />

    <TextView
        android:id="@+id/textView_language"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/_3ssp"
        android:text="Dummy"
        android:textColor="#121212"
        android:textSize="@dimen/_9ssp"
        app:layout_constraintEnd_toEndOf="@+id/navigation_button_language"
        app:layout_constraintStart_toStartOf="@+id/navigation_button_language"
        app:layout_constraintTop_toBottomOf="@+id/navigation_button_language" />

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="0dp"
        android:layout_height="@dimen/_240sdp"
        app:layout_constraintBottom_toBottomOf="@+id/linearLayout"
        app:layout_constraintEnd_toStartOf="@+id/linearLayout"
        android:layout_marginLeft="@dimen/_6sdp"
        android:layout_marginRight="@dimen/_6sdp"
        android:background="@color/colorGrey"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/linearLayout"
        app:layout_constraintVertical_bias="0.447">


        <ScrollView
            android:layout_width="47dp"
            android:layout_height="44dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" />
        </ScrollView>

        <TextView
            android:id="@+id/textView_Name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Test Name"
            android:textColor="#000000"
            android:textSize="@dimen/_14ssp"
            android:textStyle="bold"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/textView_QuantityText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_1sdp"
            android:text="Quantity: "
            android:textSize="@dimen/_9ssp"

            app:layout_constraintEnd_toEndOf="@+id/textView_Name"
            app:layout_constraintStart_toStartOf="@+id/textView_Name"
            app:layout_constraintTop_toBottomOf="@+id/textView_Name" />

        <TextView
            android:id="@+id/textView_QuantityNumber"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2"
            android:textSize="@dimen/_9ssp"
            app:layout_constraintBottom_toBottomOf="@+id/textView_QuantityText"
            app:layout_constraintStart_toEndOf="@+id/textView_QuantityText"
            app:layout_constraintTop_toTopOf="@+id/textView_QuantityText" />

        <TextView
            android:id="@+id/textView_TableNumberText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_1sdp"
            android:text="Table: "
            android:textSize="@dimen/_9ssp"
            app:layout_constraintEnd_toEndOf="@+id/textView_QuantityText"
            app:layout_constraintStart_toStartOf="@+id/textView_QuantityText"
            app:layout_constraintTop_toBottomOf="@+id/textView_QuantityText" />

        <TextView
            android:id="@+id/textView_TableNumberValue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="3"
            android:textSize="@dimen/_9ssp"
            app:layout_constraintBottom_toBottomOf="@+id/textView_TableNumberText"
            app:layout_constraintStart_toEndOf="@+id/textView_TableNumberText"
            app:layout_constraintTop_toTopOf="@+id/textView_TableNumberText" />

        <ImageButton
            android:id="@+id/imageButton_message"
            android:layout_width="@dimen/_25sdp"
            android:layout_height="@dimen/_25sdp"
            android:layout_marginTop="8dp"
            android:background="@drawable/ic_baseline_markunread_24"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.221"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView_TableNumberText" />

        <ImageButton
            android:id="@+id/imageButton_video"
            android:layout_width="@dimen/_25sdp"
            android:layout_height="@dimen/_25sdp"
            android:background="@drawable/ic_baseline_videocam_24"
            app:layout_constraintBottom_toBottomOf="@+id/imageButton_message"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.827"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/imageButton_message" />

        <TextView
            android:id="@+id/textView_message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_1sdp"
            android:text="Message"
            app:layout_constraintEnd_toEndOf="@+id/imageButton_message"
            app:layout_constraintStart_toStartOf="@+id/imageButton_message"
            app:layout_constraintTop_toBottomOf="@+id/imageButton_message" />

        <TextView
            android:id="@+id/textView_Video"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Video"
            android:layout_marginTop="@dimen/_1sdp"
            app:layout_constraintEnd_toEndOf="@+id/imageButton_video"
            app:layout_constraintStart_toStartOf="@+id/imageButton_video"
            app:layout_constraintTop_toBottomOf="@+id/imageButton_video" />


    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout> 

知道我该怎么做吗?我非常感谢您的每一条评论,并感谢您的帮助.

Any idea how I can do that? I'd highly appreciate every comment and would be thankful for your help.

提醒:没有人知道我该怎么做吗?我经常看到这样的布局,所以我想做的事情不应该是非常不寻常的.

Reminder: Does nobody have any idea how I can do that? I have seen such layouts quite often so it should not be extremely unsual what I want to do.

推荐答案

答案:

制作可绘制对象 ->rim.xml

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
     <stroke
        android:width="@dimen/space_lg"
        android:height="@dimen/space_lg"
        android:color="@color/#fff"
        android:dashGap="@dimen/space_sm" />

</shape>

并在布局中使用:

 android:background="@drawable/rim"
            

这篇关于如何在 Android 中使用带有边框和彩色区域的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆