标签: android-constraintlayout

ConstraintLayout和RelativeLayout之间的差异

我对ConstraintLayout和RelativeLayout之间的区别感到困惑.有人可以告诉我他们之间的确切差异吗?

android android-layout android-relativelayout android-constraintlayout

200
推荐指数
9
解决办法
12万
查看次数

如何使ConstraintLayout使用百分比值?

通过Android Studio 2.2的预览1,Google在其支持库中发布了一个新的布局:ConstraintLayout.使用ConstraintLayout,在Android Studio中使用设计工具更容易,但我没有找到一种方法来使用相对大小(像LinearLayout中的百分比或'权重').有没有办法根据百分比定义约束?例如,使视图占据屏幕的40%,在视图之间创建20%的边距,将视图的宽度设置为另一个视图宽度的50%?

android android-support-library android-constraintlayout

179
推荐指数
12
解决办法
12万
查看次数

如何使ConstraintLayout中的元素居中

ConstraintLayout在我的应用程序中使用来进行应用程序布局.我正在尝试创建一个屏幕,其中一个EditText并且Button应该位于中心,并且Button应该低于EditTextmarginTop仅16dp.

这是我的布局和屏幕截图,它现在看起来如何.

activity_authenticate_content.xml

<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"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    tools:context="com.icici.iciciappathon.login.AuthenticationActivity">

    <android.support.design.widget.TextInputLayout
        android:id="@+id/client_id_input_layout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/login_client_id"
            android:inputType="textEmailAddress" />

    </android.support.design.widget.TextInputLayout>

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/authenticate"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="@string/login_auth"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="@id/client_id_input_layout"
        app:layout_constraintRight_toRightOf="@id/client_id_input_layout"
        app:layout_constraintTop_toTopOf="@id/client_id_input_layout" />

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

android android-layout android-constraintlayout

176
推荐指数
7
解决办法
14万
查看次数

使用ConstraintLayout均匀地间隔视图

常见的用途LinearLayout是均匀地分隔(加权)视图,例如: 示例布局

如何使用新的实现均匀分布的视图ConstraintLayout

ConstraintLayout链接供参考:博客文章,I/O会话视频

android android-layout android-constraintlayout

153
推荐指数
5
解决办法
7万
查看次数

Gradle Sync失败找不到约束布局:1.0.0-alpha2

问题:

Error:Could not find com.android.support.constraint:constraint-layout:1.0.0-alpha2.
Required by:
myapp:app:unspecified
Run Code Online (Sandbox Code Playgroud)

背景: Android Studio 2.2 P 1

android gradle android-studio android-constraintlayout

138
推荐指数
8
解决办法
13万
查看次数

Android - 如何制作可滚动的constraintlayout?

我想制作一个允许我使用约束布局向下滚动的布局,但我不知道如何去做.如果scrollview是这样的constraintlayout的父级吗?

<?xml version="1.0" encoding="utf-8"?>

<ScrollView 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:fillViewport="true">

<android.support.constraint.ConstraintLayout
    android:id="@+id/Constraint"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)

或者相反?也许有人可以指点我这方面的好教程或举个例子,我似乎无法找到一个.

此外,我不知道这是否是一个错误或一些配置,我不已经建立,但我看到了这样的图片 一个地方有蓝图"蓝色矩形"以外的一些成分但他们是可见的,而在我的身边,如果我将一个组件放在"白色空间"上我无法看到它或将其移动到任何地方,它出现在组件树上.

UPDATE

我找到了一种方法,可以在设计工具中滚动约束布局,使用horiontal准线向下推约束布局边框并将其扩展到设备之外,之后您可以使用引导线作为约束布局的新底部锚定组件.

android android-layout android-scrollview android-constraintlayout

120
推荐指数
8
解决办法
10万
查看次数

ConstraintLayout内的Wrap_content视图在屏幕外伸展

我正在尝试使用一个简单的聊天气泡ConstraintLayout.这就是我想要实现的目标:

在此输入图像描述 在此输入图像描述

但是,wrap_content似乎没有与约束一起正常工作.它尊重边距,但不能正确计算可用空间.这是我的布局:

<?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"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/chat_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintHorizontal_bias="0"
        tools:background="@drawable/chat_message_bubble"
        tools:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris sodales accumsan tortor at bibendum."
        android:layout_marginStart="64dp"
        android:layout_marginLeft="64dp"
        android:layout_marginEnd="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

这呈现如下:

在此输入图像描述

我在用com.android.support.constraint:constraint-layout:1.0.0-beta4.

难道我做错了什么?这是一个错误还是一个不直观的行为?ConstraintLayout我可以使用(我知道我可以使用其他布局,我ConstrainLayout具体询问)来实现正确的行为.

android android-layout android-constraintlayout

107
推荐指数
5
解决办法
4万
查看次数

如何在Constraint Layout上实现重叠/负边距?

是否有可能在约束布局上实现负边距以实现重叠?我试图让一个图像以布局为中心,并有一个文本视图,使其重叠x x dp.我尝试设置负保证金值,但没有运气.如果有办法实现这一目标会很棒.

android android-constraintlayout constraint-layout-chains

90
推荐指数
5
解决办法
4万
查看次数

Android ConstraintLayout - 将一个视图放在另一个视图的顶部

我想添加ProgressBar上的顶部Button(均为内ConstraintLayout).

<Button
    android:id="@+id/sign_in_button"
    android:layout_width="280dp"
    android:layout_height="75dp"
    android:layout_marginBottom="75dp"
    android:layout_marginTop="50dp"
    android:text="@string/sign_in"
    android:textColor="@color/white"
    android:textSize="22sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/passwordEditText"
    app:layout_constraintVertical_bias="0.0"/>

<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="@+id/sign_in_button"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="@+id/sign_in_button"
    android:layout_marginBottom="8dp"
    app:layout_constraintVertical_bias="0.5"
    android:layout_marginLeft="8dp"
    app:layout_constraintLeft_toLeftOf="@+id/sign_in_button"
    android:layout_marginRight="8dp"
    app:layout_constraintRight_toRightOf="@+id/sign_in_button"/>
Run Code Online (Sandbox Code Playgroud)

但即使在呼吁bringToFront进入ProgressBaronCreate,它总是留在后面Button.

ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar);
progressBar.bringToFront();
Run Code Online (Sandbox Code Playgroud)

android android-layout android-constraintlayout

85
推荐指数
5
解决办法
4万
查看次数

是否可以将ConstraintLayout放入ScrollView中?

所以最近,与Android Studio 2.2中有一个新的ConstraintLayout,使设计轻松了很多,但不像RelativeLayout并且Linearlayout,我不能使用ScrollView包围ConstraintLayot.这可能吗?如果是这样,怎么样?

<ScrollView 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"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp">

        <android.support.constraint.ConstraintLayout
            android:id="@+id/constraintLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="0dp">

            <!-- Have whatever children you want inside -->

        </android.support.constraint.ConstraintLayout>

</ScrollView>
Run Code Online (Sandbox Code Playgroud)

user-interface android android-layout android-constraintlayout

80
推荐指数
8
解决办法
8万
查看次数