2017-08-11 174 views
5

我是Android的新手,ConstraintLayout,也是Android的新手。我有个问题。在ConstraintLayout内建议使用LinearLayout?例如:建议在Android的ConstraintLayout中使用LinearLayout?

<?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" 
    app:srcCompat="@drawable/landing_screen" 
    android:layout_height="match_parent" 
    tools:context="com.braigolabs.braigo.landing.LandingActivity"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:scaleType="centerCrop" 
     app:srcCompat="@drawable/landing_screen" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintVertical_bias="1.0" 
     app:layout_constraintHorizontal_bias="1.0" 
     tools:layout_constraintTop_creator="1" 
     tools:layout_constraintRight_creator="1" 
     tools:layout_constraintBottom_creator="1" 
     tools:layout_constraintLeft_creator="1"/> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     tools:layout_editor_absoluteX="0dp" 
     tools:layout_editor_absoluteY="51dp"> 

     <TextView 
      android:id="@+id/textView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="66dp" 
      android:layout_marginStart="66dp" 
      android:gravity="center" 
      android:text="@string/login_welcome_braigolabs"    android:textAppearance="@style/TextAppearance.AppCompat.Large" 
      tools:layout_editor_absoluteX="93dp" 
      tools:layout_editor_absoluteY="403dp"/> 

     <Button 
      android:id="@+id/login_button" 
      style="@style/Widget.AppCompat.Button.Colored" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:elevation="2dp" 
      android:text="@string/login_login_button_title" 
      android:textAllCaps="false" 
      tools:layout_editor_absoluteX="116dp" 
      tools:layout_editor_absoluteY="543dp"/> 
    </LinearLayout> 
</android.support.constraint.ConstraintLayout> 

还想知道在开发者当中ConstraintLayout有多受欢迎?

回答

9

建议在ConstraintLayout中使用LinearLayout吗?

不...通常。

一般来说,ConstraintLayout背后的想法是,它允许您定位所有的孩子,而不必在ConstraintLayout中嵌套任何其他ViewGroup。因此,我会说这不是建议

然而,有一些事情,一个LinearLayout可以做一个ConstraintLayout不能(主要是围绕观点加权间距旋转),所以如果你需要在你的布局这些特殊的角落情况下,你不会除了回落到LinearLayout以外,还有其他选择。

ConstraintLayout在开发人员中的受欢迎程度如何?

ConstraintLayout是比较新的,但它是相当强大的,肯定是你应该熟悉的东西。它并不总是手头工作的完美工具,但它通常会让您轻松创建布局,否则您将花费​​数小时。

我无法与广泛采用的统计数据进行对话,但我可以说我已经在这个网站上看到很多关于ConstraintLayout的正确用法的问题,所以全世界的开发人员都开始使用它。

+0

完美。谢谢@Ben。为什么有人投降?这是一个相当相关的问题。 – TechBee

+0

我不能肯定地说,但我相信你的问题总的来说是要求_opinion_,而不是提出具体的编程问题。这通常被认为是无关紧要的。 –

相关问题