【发布时间】:2018-10-28 21:31:07
【问题描述】:
所以我想在布局中的 ViewPager 元素下方显示两个按钮。我无法在模拟器或布局检查器中看到。这是我设置的布局 xml。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:text="@string/first_crime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/first_button"
android:layout_gravity="bottom"
android:layout_margin="16dp"/>
<Button
android:text="@string/last_crime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/last_button"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"/>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/crime_view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
</android.support.v4.view.ViewPager>
</FrameLayout>
这是它在设计工具中的样子。
这是第二种方法。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/crime_view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
</android.support.v4.view.ViewPager>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" 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">
<Button
android:id="@+id/first_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/first_crime"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent" />
<Button
android:id="@+id/last_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:text="@string/last_crime"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>
</FrameLayout>
这是它在设计模式下的样子。
我想在我的模拟器中看到屏幕底部的按钮。这是我看到的。
更新我已经使用 ConstraintLayout 更新了布局,但我仍然看不到模拟器中的按钮。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" 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">
<Button
android:id="@+id/first_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/first_crime"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent" />
<Button
android:id="@+id/last_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:text="@string/last_crime"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/crime_view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
</android.support.v4.view.ViewPager>
</FrameLayout>
这是 ViewPager 元素内显示的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:listSeparatorTextViewStyle"
android:text="@string/crime_title_label"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/crime_title_hint"
android:id="@+id/crime_title_text"
android:inputType="none"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:listSeparatorTextViewStyle"
android:text="@string/crime_details_label"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:padding="80dp"
android:id="@+id/crime_date_button"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/crime_solved_label"
android:id="@+id/crime_solved"/>
</LinearLayout>
我正在学习 Android 编程,所以如果我排除了任何其他信息,那么我很乐意提供这些信息。
【问题讨论】:
标签: android android-layout android-viewpager