'view' 容器在 Android 的 XML 中有什么作用 [英] What does 'view' container do in XML of Android
本文介绍了'view' 容器在 Android 的 XML 中有什么作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这个 XML 中使用 view 有什么好处?
In this XML what is advantage of using view?
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout android:id="@+id/coordinatorLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/view"
android:layout_width="100dp"
android:layout_height="720dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/toggleBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="72dp"
android:text="@string/toggle_screen"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:text="@string/primary_screen"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@+id/toggleBtn"
app:layout_constraintStart_toStartOf="@+id/toggleBtn"
app:layout_constraintTop_toBottomOf="@+id/toggleBtn" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我在使用和不使用 view 的情况下测试了代码,我没有看到它在设备上的输出有任何不同.XML中view的一般用法是什么?感谢您的帮助.
I tested the code with and without view and I didn't see any difference in its output on device. Generally what is usage of view in XML? Thanks for any help.
推荐答案
我觉得在这段代码中,查看应用很清楚:
I think in this code, view application is clear:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:tabGravity="fill"
app:tabMode="fixed" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#c6c4c4" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
当视图在 xml 输出中时:
When view is in xml output will be:
但是在 xml 输出中没有视图将是:
But without view in xml output will be:
这篇关于'view' 容器在 Android 的 XML 中有什么作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文