Как я могу создать этот дизайн в Android, используя XML? - PullRequest
0 голосов
/ 21 апреля 2020

Я пытаюсь создать этот дизайн, показанный на рисунке ниже.

Но я понятия не имею, как мне начать делать это, используя XML. Я имею в виду, например, строку, содержащую круг и слово VS. Как я должен сделать это в XML?

Есть идея или пример?

enter image description here

1 Ответ

1 голос
/ 21 апреля 2020

Я спроектировал необходимый вам xml файл: D Я надеюсь, что это поможет:

вот мгновенный магазин: Preview

Сначала вы должны загрузите изображения ниже и добавьте в свой каталог для рисования

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

маска изображения

Далее следует скопировать ниже xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="#fff"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center">



            <ImageView
                android:layout_width="150dp"
                android:layout_height="150dp"
                android:background="#9C9C9C" />

            <ImageView
                android:layout_width="150dp"
                android:layout_height="150dp"
                android:background="@drawable/profilemask" />

        </RelativeLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tyler Gilbert"
                android:textColor="#000"
                android:textSize="25dp" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_margin="10dp"
                    android:background="#9C9C9C" />


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Algeria"
                    android:textColor="#000"
                    android:textSize="15dp" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Level : "
                    android:textColor="#000"
                    android:textSize="20dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="A1"
                    android:textColor="#BF360C"
                    android:textSize="20dp" />


            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

    <ImageView
        android:id="@+id/imgVS"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:background="@drawable/vs" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#f7f7f7"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Roger Lawson"
                android:textColor="#000"
                android:textSize="25dp" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_margin="10dp"
                    android:background="#9C9C9C" />


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Algeria"
                    android:textColor="#000"
                    android:textSize="15dp" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Level : "
                    android:textColor="#000"
                    android:textSize="20dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="A1"
                    android:textColor="#BF360C"
                    android:textSize="20dp" />


            </LinearLayout>

        </LinearLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center">



            <ImageView
                android:layout_width="150dp"
                android:layout_height="150dp"
                android:background="#9C9C9C" />

            <ImageView
                android:layout_width="150dp"
                android:layout_height="150dp"
                android:backgroundTint="#f7f7f7"
                android:background="@drawable/profilemask" />

        </RelativeLayout>

    </LinearLayout>

</LinearLayout>

, а затем, чтобы установить правильный динамический размер c для файла изображения vs, скопируйте приведенный ниже код в файл onCreate Java:

ImageView imgVS = findViewById(R.id.imgVS);

DisplayMetrics metrics = getResources().getDisplayMetrics();
int width = metrics.widthPixels;

LinearLayout.LayoutParams map = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (width * 132 / 362));
imgVS.setLayoutParams(map);

GoodLuck!

...