【问题标题】:How can I create this design in Android using XML?如何使用 XML 在 Android 中创建此设计?
【发布时间】:2020-04-22 01:45:08
【问题描述】:

我正在尝试创建如下图所示的设计。

但我不知道如何开始使用 XML 制作它。 我的意思是,这里例如包含一个圆圈和 VS 单词的行。我应该如何在 XML 中实现它?

有什么想法或例子吗?

【问题讨论】:

  • 您可以使用形状属性来创建类似使用 xml 的 pfp 布局,您可以查看这个已回答的问题>>stackoverflow.com/questions/53407101/…
  • 如果您不明白,请告诉我,我会为您创建一个这样的布局
  • 你能帮我举个例子吗

标签: android xml android-layout


【解决方案1】:

我已经设计了您需要的 xml 文件 :D 希望对你有帮助:

这里是快照商店:

首先你必须下载下面的图片并添加到你的drawable目录

vs image

mask image

接下来是复制下面的xml文件:

<?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>

然后,要为“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);

祝你好运!

【讨论】:

  • 欢迎您。如果这是您问题的答案,请接受我的回答。 tnx
猜你喜欢
  • 1970-01-01
  • 2023-01-03
  • 1970-01-01
  • 1970-01-01
  • 2021-06-30
  • 2017-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多