简体   繁体   English

Android中心图像和裁剪

[英]Android center image and crop

im with a problem related to android UI Design. 即时通讯与Android UI设计相关的问题。

This is what i want: http://i.imgur.com/a7DLo4x.jpg 这就是我想要的: http : //i.imgur.com/a7DLo4x.jpg

This is what i have: http://i.imgur.com/AnL3cHT.jpg 这就是我所拥有的: http : //i.imgur.com/AnL3cHT.jpg

I found a smiliar post about this, but their solution didnt help me: Android background Image to fill screen 我发现了一个关于此的贴子,但是他们的解决方案并没有帮助我: Android背景图片填满整个屏幕

This is my XML code: 这是我的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>

I also tried to use android:scaleType="centerCrop" 我也尝试使用android:scaleType =“ centerCrop”

Thanks for your time. 谢谢你的时间。

you have android:scaleType="center" 你有android:scaleType="center"

you need android:scaleType="centerCrop" 您需要android:scaleType="centerCrop"

I think you are using the wrong element to fill the ImageView. 我认为您使用了错误的元素来填充ImageView。 Please avoid using background element. 请避免使用背景元素。 Use src(source) element. 使用src(source)元素。 It should then work fine. 然后应该可以正常工作。

 android:src

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM