Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中设计TextView右侧的小点_Android_Android Layout_Button_Textview - Fatal编程技术网

如何在Android中设计TextView右侧的小点

如何在Android中设计TextView右侧的小点,android,android-layout,button,textview,Android,Android Layout,Button,Textview,如何在原生Android中实现这些UI,我在TextView中使用circle Drawable尝试了drawableRight,但没有得到确切的结果 带有线性布局: <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="top" android:orientation="horizontal">


如何在原生Android中实现这些UI,我在TextView中使用circle Drawable尝试了drawableRight,但没有得到确切的结果

带有线性布局

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="top"
    android:orientation="horizontal">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SORT"/>
    <ImageView
        android:layout_width="10dp"
        android:layout_height="10dp"
        android:src="@mipmap/ic_launcher"/>
</LinearLayout>

结果:

根据需要添加填充或边距;)

这是布局图

    <?xml version="1.0" encoding="utf-8"?>
        <android.support.constraint.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="50dp">`enter code here`


            <TextView
                android:id="@+id/img_notification"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:padding="10dp"
                android:text="SORT"
                android:src="@drawable/ic_bell"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                tools:ignore="ContentDescription" />

            <TextView
                android:id="@+id/txt_notification_count"
                android:layout_width="8dp"
                android:layout_height="8dp"
                android:layout_marginEnd="4dp"
                android:background="@drawable/background_rounded_bottom_count"
                android:gravity="center"
                android:textColor="@color/white"
                android:textSize="12sp"
                android:visibility="visible"
                app:layout_constraintEnd_toEndOf="@+id/img_notification"
                app:layout_constraintTop_toTopOf="@+id/img_notification" /> </android.support.constraint.ConstraintLayout>

`在这里输入代码`
XML可绘制:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="@color/colorPrimary" />
</shape>

尝试使用此代码设计相同的视图

main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello Text"
            android:textColor="#000"
            android:textSize="18sp"/>
        <LinearLayout
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:background="@drawable/pink_circle"
            android:paddingLeft="2dp"/>
    </LinearLayout>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape
    android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid
    android:color="#F04B82"/>
</shape>
<?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:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/txt_dot"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/img_circle"
        android:layout_width="12dp"
        android:layout_height="12dp"
        android:src="@drawable/circle_draw"
        app:layout_constraintTop_toTopOf="@id/txt_dot"
        app:layout_constraintStart_toEndOf="@id/txt_dot" />
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#F04B82" />

</shape>

pink\u circle.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello Text"
            android:textColor="#000"
            android:textSize="18sp"/>
        <LinearLayout
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:background="@drawable/pink_circle"
            android:paddingLeft="2dp"/>
    </LinearLayout>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape
    android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid
    android:color="#F04B82"/>
</shape>
<?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:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/txt_dot"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/img_circle"
        android:layout_width="12dp"
        android:layout_height="12dp"
        android:src="@drawable/circle_draw"
        app:layout_constraintTop_toTopOf="@id/txt_dot"
        app:layout_constraintStart_toEndOf="@id/txt_dot" />
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#F04B82" />

</shape>

试试这个:
layout_file.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello Text"
            android:textColor="#000"
            android:textSize="18sp"/>
        <LinearLayout
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:background="@drawable/pink_circle"
            android:paddingLeft="2dp"/>
    </LinearLayout>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape
    android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid
    android:color="#F04B82"/>
</shape>
<?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:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/txt_dot"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/img_circle"
        android:layout_width="12dp"
        android:layout_height="12dp"
        android:src="@drawable/circle_draw"
        app:layout_constraintTop_toTopOf="@id/txt_dot"
        app:layout_constraintStart_toEndOf="@id/txt_dot" />
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#F04B82" />

</shape>

circle\u draw.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello Text"
            android:textColor="#000"
            android:textSize="18sp"/>
        <LinearLayout
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:background="@drawable/pink_circle"
            android:paddingLeft="2dp"/>
    </LinearLayout>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape
    android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid
    android:color="#F04B82"/>
</shape>
<?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:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/txt_dot"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/img_circle"
        android:layout_width="12dp"
        android:layout_height="12dp"
        android:src="@drawable/circle_draw"
        app:layout_constraintTop_toTopOf="@id/txt_dot"
        app:layout_constraintStart_toEndOf="@id/txt_dot" />
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#F04B82" />

</shape>


使用水平线性布局和TextView和ImageView是没有选择的?我发现了这一点。检查它是否工作,你能提供最低工作代码吗?