【发布时间】:2018-03-29 15:50:14
【问题描述】:
我是 XML 新手,想创建一个简单的游戏起始页。首先,我从 Android Studio 3.0 Layout maker 开始,并想出了这样的东西(第二张图片)。最大的问题是获取右下角的 3 个 ImageButtons。经过大量尝试和谷歌我找不到解决方案,是否可以仅使用 XML 代码?
<?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="match_parent"
android:background="@color/colorPrimary"
tools:context="de.chipsapps.ca.identiti.MenuACT">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="220dp"
android:layout_height="220dp"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:cropToPadding="false"
app:srcCompat="@drawable/logo" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/buttons_style1"
android:textColor="@color/colorPrimaryFont"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:text="@string/play"
android:textSize="30sp" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColor="@color/colorPrimaryFont"
android:background="@drawable/buttons_style1"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:text="@string/rate"
android:textSize="30sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_margin="15dp"
android:layout_weight="0.33"
android:adjustViewBounds="false"
android:background="@drawable/button_style2"
android:cropToPadding="false"
android:scaleType="centerInside"
app:srcCompat="@drawable/settings" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="0.33"
android:scaleType="centerInside"
android:layout_margin="15dp"
android:background="@drawable/button_style2"
app:srcCompat="@drawable/highscores" />
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="0.33"
android:scaleType="centerInside"
android:layout_margin="15dp"
android:background="@drawable/button_style2"
app:srcCompat="@drawable/share" />
</LinearLayout>
</LinearLayout>
是否可以使用 XML 来获取? 希望有人可以提供帮助:D
编辑尝试了这个:
<?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="match_parent"
android:background="@color/colorPrimary"
tools:context="de.chipsapps.ca.identiti.MenuACT">
<View
android:id="@+id/bigCircle"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="48dp"
android:background="@drawable/logo"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintWidth_percent=".5"/>
但看起来是这样的:
【问题讨论】:
-
首先使用较小分辨率的图像,并从两侧添加一些边距或使用weightsum
-
我必须在哪里使用 weightsum?
标签: java android xml android-studio-3.0