是否建议在Android的ConstraintLayout中使用LinearLayout? [英] Is it advisable to use LinearLayout inside ConstraintLayout in Android?

查看:131
本文介绍了是否建议在Android的ConstraintLayout中使用LinearLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to ConstraintLayout in Android and newbie to Android too. I have a question. Is it advisable to use LinearLayout inside ConstraintLayout? For example:

<?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在开发人员中有多受欢迎?

Also curious to know how popular is the ConstraintLayout among the developers?

推荐答案

建议在ConstraintLayout中使用LinearLayout吗?

Is it advisable to use LinearLayout inside ConstraintLayout?

不...通常.

通常,ConstraintLayout的想法是,它使您可以放置​​所有孩子,而不必在ConstraintLayout内嵌套任何其他ViewGroup.因此,我想说这不是可取的.

In general, the idea behind ConstraintLayout is that it allows you to position all of your children without having to nest any other ViewGroups inside the ConstraintLayout. As such, I would say that it is not advisable.

但是,有些 LinearLayout可以做到的,ConstraintLayout不能做到(主要围绕视图的加权间距),因此,如果需要这些特殊的极端情况,在您的版式中,除了退回LinearLayout之外,您别无选择.

However, there are some things that a LinearLayout can do that a ConstraintLayout can't (mostly revolving around weighted spacing of views), and so if you need these particular corner cases in your layout, you won't have any option other than falling back to a LinearLayout.

ConstraintLayout在开发人员中有多受欢迎?

how popular is the ConstraintLayout among the developers?

ConstraintLayout相对较新,但是功能非常强大,当然您应该熟悉一下.它并不是始终是完成当前工作的理想工具,但是它通常可以使您轻松地创建原本会花费数小时的版面.

ConstraintLayout is relatively new, but it is quite powerful and certainly something that you ought to familiarize yourself with. It won't always be the perfect tool for the job at hand, but it will often allow you to easily create layouts you would otherwise spend hours on.

我无法谈及广泛采用的统计数据,但是我可以说我在该站点上看到了很多有关ConstraintLayout正确用法的问题,因此很明显,全世界的开发人员都开始使用它.

I can't speak to widespread adoption statistics, but I can say that I've seen tons of questions on this site about the correct usage of ConstraintLayout, so clearly devs around the world are starting to work with it.

这篇关于是否建议在Android的ConstraintLayout中使用LinearLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆