4Manuals

  • PDF Cloud HOME

如何使用约束布局将屏幕分成两个相等的部分? Download

    如何在Android中使用WebRTC缩放相机 Android 10,API29:在应用程序文件夹中使用C ++库编写文件会使应用程序崩溃 如何将动态值传递给渐变xml 加载数据并推送到未显示的RecyclerView中 调用Model类的函数时出现java.lang.NullPointerException 从网络加载图像时,“接收到完整的报头之前关闭连接 Ionic 3错误:“缺少文件google-services.json。没有它,Google Services插件将无法运行。”在离子科尔多瓦建立/准备Android androidx.appcompat.view.menu.MenuItemImpl无法转换为android.widget.TextView 从Firebase发送推送通知不起作用 Ljava / applet / Applet上的Android LDAP / NoClassDefFoundError;

我想使用约束布局将屏幕分成两半吗?我只能找到相对和线性布局的示例,有人可以帮助我吗?我附上了一张有关其外观的屏幕截图。Image attached

1 个答案:

答案 0 :(得分:0)

执行此操作的最好方法是使用<GuideLine />

<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.support.constraint.Guideline
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/guideline"
            app:layout_constraintGuide_percent="50%"
            android:orientation="horizontal"/>

    <TextView
            android:text="Text 1"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:id="@+id/button"
            android:gravity="center"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@+id/guideline" />

    <TextView
            android:text="Text 2"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:id="@+id/button"
            android:gravity="center"
            app:layout_constraintBottom_toTopOf="@+id/guideline"
            app:layout_constraintBottom_toBottomOf="parent" />

</android.support.constraint.ConstraintLayout>

有关android约束布局指南的更多信息,您可以阅读其官方文档here

Here's另一篇很棒的文章,用于学习如何使用准则



Similar searches
    如何使用多个数据集训练LSTM? 想要让Nav-Item与Nav-Bar的高度相同 关于在Bernoulli分布之后用R中的概率矩阵生成随机数矩阵 Logstash sql_last_value未更新 在自定义类Bootstap 4中的Sass中使用margin和padding变量