Android背景图像-图像视图
我有一个活动,我将imageview元素设置为将父对象与我的一个尺寸为1440x2560的背景图像相匹配。我需要在fullscrean上制作这个图像。但每当我使用scaleType=“fitXY”放置该图像时,我都会得到以下结果: XML布局:Android背景图像-图像视图,android,android-imageview,Android,Android Imageview,我有一个活动,我将imageview元素设置为将父对象与我的一个尺寸为1440x2560的背景图像相匹配。我需要在fullscrean上制作这个图像。但每当我使用scaleType=“fitXY”放置该图像时,我都会得到以下结果: XML布局: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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.backgroundApp.SecondActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@drawable/background"
android:scaleType="fitXY"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
package com.backgroundApp;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class SecondActivity extends AppCompatActivity {
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#004d40")));
}
}
在图像视图中使用adjustViewBounds=true属性
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@drawable/background"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
使用
<ImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
setAdjustViewBounds(布尔adjustViewBounds)
如果希望ImageView调整其边界以保留其可绘制的纵横比,请将其设置为true。
<ImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
改变
app:srcCompat="@drawable/background"
到
您是否尝试过
scaletype=centerCrop
?您已经找到答案了吗?@AjilO。它有点大,但又不是全屏…@SteveYo你确定你做的一切都对吗?这篇文章中的两个答案对我都有用。尝试使用其他图像我收到此错误:错误:(9)在包“com.backgroundApp”中找不到属性“adjustViewBounds”的资源标识符。请检查我更改了我的回答也尝试了使用android,但仍然得到了不在fullscrean上的相同图像:/我收到此错误:错误:(9)在包“com.backgroundApp”declare name space xmlns:app=”“中找不到属性“adjustViewBounds”的资源标识符也尝试使用android,但仍然得到与fullscrean上不存在的相同图像:/试着设置programaticaaly@SteveYo
android:src="@drawable/xxxxx"