【发布时间】:2018-06-10 22:43:32
【问题描述】:
我正在尝试创建以下布局。我已经读过约束布局是我应该使我的布局响应。我尝试将我的约束布局包含在线性布局中,希望对齐可以修复但无济于事。 (不确定我的做法是否正确)
非常感谢任何帮助。
这是它在 android studio 中的样子:
这是我的 xml 代码:
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_rightwashed"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/menu_btn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:background="@drawable/burger_btn" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/calendar_btn"
android:layout_width="190dp"
android:layout_height="190dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@android:color/transparent"
android:layoutDirection="inherit"
android:src="@drawable/calendartrain"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.48000002" />
<ImageView
android:id="@+id/skillstree_btn"
android:layout_width="190dp"
android:layout_height="190dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layoutDirection="inherit"
android:src="@drawable/skillstreetrain"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.04"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.58000004" />
<ImageView
android:id="@+id/completed_btn"
android:layout_width="190dp"
android:layout_height="190dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layoutDirection="inherit"
android:src="@drawable/completedtrain"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.22"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.24000001" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
<RelativeLayout
android:id="@+id/leftDrawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light" />
<include
layout="@layout/drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
【问题讨论】:
-
为什么必须有三个不同的
ImageViews? -
@Jantzilla 每个按钮都应该打开一个不同的视图,这就是为什么我有 3 个。我为三个图像视图中的每一个添加了一个 onClickListener。
-
您应该可以使用一个
ImageView并设置一个触摸监听器来检索坐标并根据触摸位置打开不同的视图。
标签: android android-layout android-studio android-constraintlayout