小编dav*_*123的帖子

垂直拉伸ImageView约束布局

在使ImageView垂直填充剩余的间隙时,我遇到了一个小问题。我在屏幕截图上以红色突出显示了它。有人可以看看并提供建议吗?

https://i.stack.imgur.com/PBio1.png

这是关联的XML代码:

<?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="match_parent"
    tools:context="com.example.android.happybirthday.MainActivity">

<ImageView
    android:id="@+id/imageView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:contentDescription="@string/happy_birthday_toyou"
    android:scaleType="centerCrop"
    android:src="@drawable/invite"
    app:layout_constraintBottom_toTopOf="@+id/textViewBottom"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textViewTop" />

<TextView
    android:id="@+id/textViewTop"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:padding="8dp"
    android:fontFamily="sans-serif"
    android:text="@string/happy_birthday_toyou"
    android:textColor="@color/colorWhite"
    android:background="@color/colorBlack"
    android:textSize="@dimen/text_size"
    android:gravity="start"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintStart_toStartOf="parent"
   />

<TextView
    android:id="@+id/textViewBottom"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:background="@color/colorBlack"
    android:fontFamily="sans-serif"
    android:gravity="end"
    android:padding="8dp"
    android:text="@string/from_me"
    android:textColor="@color/colorWhite"
    android:textSize="@dimen/text_size"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    />



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

android imageview android-layout

3
推荐指数
1
解决办法
1398
查看次数

使用layout_constraintVertical_weight分发TextView

我有一个小问题layout_constraintVertical_weight,我试图使两个TextView共享分配的区域中可用的垂直空间,但是没有我的手动分配就不会发生。我试过增加0dp高度,但这是行不通的,但是对于宽度,它可以完美地工作。这是我的XML:

    <?xml version="1.0" encoding="utf-8"?>
    <!-- Layout for a single list item -->
    <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="@dimen/list_item_height"
        android:background="@color/tan_background">

        <ImageView
            android:id="@+id/image"
            android:layout_width="@dimen/list_item_height"
            android:layout_height="@dimen/list_item_height"
            android:src="@mipmap/ic_launcher" />

        <TextView
            android:id="@+id/miwok_text_view"
            android:layout_width="0dp"
            android:layout_height="44dp"
            android:background="@color/category_colors"
            app:layout_constraintLeft_toRightOf="@+id/image"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_weight="1"
            tools:text="text1" />

        <TextView
            android:id="@+id/default_text_view"
            android:layout_width="0dp"
            android:layout_height="44dp"
            android:background="@color/category_numbers"
            app:layout_constraintLeft_toRightOf="@+id/image"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintVertical_weight="1"
            tools:text="text2" />

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

这是布局外观的img:https : //i.stack.imgur.com/ZOs9y.png

android textview android-constraintlayout

1
推荐指数
1
解决办法
2723
查看次数