Android背景图像 - imageview
我有一个活动,我设置了imageview元素,以匹配家长与我的背景图像之一与维度:1440x2560。我需要使这个形象充分。但每当我把使用scaleType = “fitXY” 的形象我得到这个: Android背景图像 - imageview
XML布局:
<?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 =真 property in ImageView tag like
<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"/>
setAdjustViewBounds(boolean 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"/>
或尝试设置编程
imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setAdjustViewBounds(true);
我收到此错误:错误:(9)找不到包含'com.backgroundApp'属性'adjustViewBounds'的资源标识符 – SteveYo
声明名称空间xmlns:app =“http://schemas.android.com/apk/ res-auto“ –
请尝试使用android:adjustViewBounds。它会工作 –
变化
app:srcCompat="@drawable/background"
到
android:src="@drawable/xxxxx"
你尝试'scaletype = centerCrop'? –
你已经有答案了吗? – UmarZaii
@AjilO。它有点大,但不是全屏... – SteveYo