【问题标题】:How to position an imageview 1/3 of the way down the screen?如何将图像视图定位在屏幕下方的 1/3 处?
【发布时间】:2022-07-26 21:27:34
【问题描述】:

我正在尝试将图像视图放置在屏幕下方大约 1/3 的位置,然后 最重要的是,我需要它在多个设备上工作,所以它不能只是一个设定的 dp 值。我不介意它是否使用 ConstraitLayout 的 RelativeLayout。图片代码如下:

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_centerHorizontal="true"
        android:contentDescription="@null"
        android:src="@drawable/ic_logo_100"/>

有谁知道如何做到这一点?如果您对我的问题有任何疑问,请告诉我:)

【问题讨论】:

  • 你能添加图片任何描述

标签: android android-layout


【解决方案1】:

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintGuide_percent="0.66"
        android:orientation="horizontal" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:contentDescription="@null"
        android:src="@drawable/ic_logo_100"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline" />
    
</androidx.constraintlayout.widget.ConstraintLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多