当前位置: 首页 > 知识库问答 >
问题:

使用ConstraintLayout-Android时未完全显示视图内容

莫英卓
2023-03-14
app:layout_constraintRight_toRightOf="@+id/colorPicker"
app:layout_constraintLeft_toLeftOf="@+id/colorPicker"

有人能解释这种行为以及如何修复它吗?

我为此使用的完整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"
    tools:context="xxx.xxx.xxx.MainActivity">

    <com.rarepebble.colorpicker.ColorPickerView
        android:id="@+id/colorPicker"
        android:layout_width="wrap_content"
        android:layout_height="0dp"

        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/guideline"

        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        />

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintGuide_percent="0.60"
        android:orientation="horizontal"
        />

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Hello World! Some chars in this TextView are cut on the right side."

        app:layout_constraintTop_toTopOf="@+id/guideline"
        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintRight_toRightOf="@+id/colorPicker"
        app:layout_constraintLeft_toLeftOf="@+id/colorPicker"
        />

</android.support.constraint.ConstraintLayout>

共有1个答案

卢黎昕
2023-03-14

您是否尝试使用LinearLayout?对于像这样的问题,一个视图需要占据一定比例的屏幕,使用layout_weight

使用LinearLayout的解决方案

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:orientation="vertical">
        <com.rarepebble.colorpicker.ColorPickerView
            android:id="@+id/colorPicker"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_gravity="center"
            android:layout_weight="6"
            />
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="4">
            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Hello World! Some chars in this TextView are cut on the right side." />
        </FrameLayout>
</LinearLayout>

基于注释进行编辑

<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.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fabSize="normal"
        android:layout_marginStart="16dp"
        app:layout_constraintLeft_toLeftOf="@+id/linearContainer"
        app:layout_constraintTop_toTopOf="@+id/linearContainer"
        android:layout_marginTop="16dp" />

    <View
        android:id="@+id/view"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="0dp"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="0dp"
        android:layout_marginTop="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    <LinearLayout
        android:id="@+id/linearContainer"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginBottom="0dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintVertical_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent">

        <com.rarepebble.colorpicker.ColorPickerView
            android:id="@+id/colorPicker"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_gravity="center"
            android:layout_weight="6" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="4">

            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Hello World! Some chars in this TextView are cut on the right side." />
        </FrameLayout>
    </LinearLayout>

</android.support.constraint.ConstraintLayout>
 类似资料:
  • 嗨,我正在尝试创建一个模式内的地图。但是地图只显示了一部分。我尝试过在节点创建后使其无效,但它似乎不起作用。谢谢!

  • 我有一个自定义背景编辑文本。当他们的键盘打开-屏幕调整显示集中编辑文本,问题是,它削减了我的自定义背景。 什么是最好的方式显示我的编辑文本包括他的敲击白背景时,键盘打开? 我的清单现在是调整设置。

  • 编写Web应用可能是单调的,因为你需要不断的重复某一种模式。 Django尝试从model和 template层移除一些单调的情况,但是Web开发者依然会在view(视图)层经历这种厌烦。 Django的通用视图被开发用来消除这一痛苦。它们采用某些常见的习语和在开发过 程中发现的模式然后把它们抽象出来,以便你能够写更少的代码快速的实现基础的视图。 我们能够识别一些基础的任务,比如展示对象的列表,以

  • 我试图设计一个弹出窗口。我设计了它,它的工作原理,但有一个小问题。这是弹出窗口代码的一部分: 这就是我所说的: 弹出窗口在应该工作的时候工作。但是其中的内容没有完全显示。这是屏幕截图: 如何解决这个问题?

  • 我正在制作一个应用程序,其中有回收器视图。但我无法在我的应用程序中看到回收器视图。当我检查Logcat时,它显示'e/recyclerview:No adapter attached;正在跳过布局‘。为什么会发生这种情况,我该如何修复? 我的主要活动代码: 我的适配器(PostAdapter.java)类代码:

  • 问题内容: 这是我有趣的问题。当应用未运行时,来自GCM的Android通知未显示标题和内容( 仅 显示应用名称,并且在单击时打开MainActivity)。 但是,当应用程序打开时,它会 成功 显示标题和内容。可能是什么问题?它运行没有问题,我没有进行任何更改。 表现: GcmService.java: 谢谢。 在应用程序运行时记录。 应用未运行时记录。 问题答案: 找到了问题。我使用的是Pla