簡體   English   中英

Android中心圖像和裁剪

[英]Android center image and crop

即時通訊與Android UI設計相關的問題。

這就是我想要的: http : //i.imgur.com/a7DLo4x.jpg

這就是我所擁有的: http : //i.imgur.com/AnL3cHT.jpg

我發現了一個關於此的貼子,但是他們的解決方案並沒有幫助我: Android背景圖片填滿整個屏幕

這是我的XML代碼:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:alwaysDrawnWithCache="false">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageView"
        android:scaleType="center"
        android:background="@drawable/bg" />


   <!-- <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/logoImage"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/logo"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
-->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Login"
        android:id="@+id/loginBt"
        android:layout_below="@+id/logoImage"
        android:layout_alignStart="@+id/logoImage"
        android:layout_marginTop="5dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Register"
        android:id="@+id/registerBt"
        android:layout_alignBottom="@+id/loginBt"
        android:layout_alignRight="@+id/loginBt"
        android:layout_alignEnd="@+id/logoImage"
        android:layout_marginTop="5dp" />

    <FrameLayout
        android:id="@+id/loginFragment"
        android:layout_width="fill_parent"
        android:layout_height="match_parent">

    </FrameLayout>



</RelativeLayout>

我也嘗試使用android:scaleType =“ centerCrop”

謝謝你的時間。

你有android:scaleType="center"

您需要android:scaleType="centerCrop"

我認為您使用了錯誤的元素來填充ImageView。 請避免使用背景元素。 使用src(source)元素。 然后應該可以正常工作。

 android:src

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM