Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – ConstraintLayout中layout_above的替代方法是什么?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试过app:layout_consTraintBottom_toTopOf =“@ id / the_view_which_will_remain_below”,但它不是所需的输出.
我想从RelativeLayout的layout_above中获得相同的行为.

使用此代码,我的Textview开始从底部出现,随着字符增加文本进入上面.但我希望文本从父母的开始开始.

<?xml version="1.0" encoding="utf-8"?>
<android.support.consTraint.ConsTraintLayout xmlns:android="http://scheR_765_11845@as.android.com/apk/res/android"
    xmlns:app="http://scheR_765_11845@as.android.com/apk/res-auto"
    xmlns:tools="http://scheR_765_11845@as.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context="com.fatimamostafa.restfulwebservices.asynctask.AsyncTaskrequest">
    <LinearLayout
        android:id="@+id/ll"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="2"
        app:layout_consTraintLeft_toLeftOf="parent"
        app:layout_consTraintright_toRightOf="parent"
        app:layout_consTraintBottom_toBottomOf="parent">

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Run" />

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Clear" />

    </LinearLayout>
    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_consTraintStart_toStartOf="parent"
        app:layout_consTraintBottom_toTopOf="@id/ll"
        app:layout_consTraintLeft_toLeftOf="parent"
        app:layout_consTraintright_toRightOf="parent"
        android:textSize="160sp"
        android:text="Text"
      />


</android.support.consTraint.ConsTraintLayout>

解决方法

要将文本放在父级的顶部,将LinearLayout放在底部,将文本视图的顶部绑定到父级,并从LinearLayout取消约束它:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Text"
    android:textSize="160sp"

    app:layout_consTraintLeft_toLeftOf="parent"
    app:layout_consTraintright_toRightOf="parent"

    app:layout_consTraintTop_toTopOf="parent"

     />

<LinearLayout
    android:id="@+id/ll"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="2"
    app:layout_consTraintLeft_toLeftOf="parent"
    app:layout_consTraintright_toRightOf="parent"
    app:layout_consTraintBottom_toBottomOf="parent"
   >

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Run" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Clear" />

</LinearLayout>

删除了一些我认为多余的约束.

另请注意,您可以使用“@ id”代替@id将TextView放在LinearLayout上.

如果要约束在父顶部和线性布局之间浮动的文本,请将这些约束添加到TextView,并调整0到1之间的垂直偏差.

app:layout_consTraintBottom_toTopOf="@+id/ll"
app:layout_consTraintVertical_bias="0.2"

大佬总结

以上是大佬教程为你收集整理的android – ConstraintLayout中layout_above的替代方法是什么?全部内容,希望文章能够帮你解决android – ConstraintLayout中layout_above的替代方法是什么?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。