【发布时间】:2015-05-15 14:46:21
【问题描述】:
对于我正在开发的应用程序的想法,我需要一些帮助。
我有一个主要活动,它的背景图像比屏幕宽,我想让该图像看起来像 Android 主屏幕一样
但我无法让背景 ImageView 表现得像它。
这是我的代码:
主活动:
// slide effect in background
background = (ImageView) findViewById(R.id.imgBackMain);
backgroundAnim = new TranslateAnimation(TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE,
100f, TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, 0f);
backgroundAnim.setDuration(10000);
backgroundAnim.setRepeatCount(-1);
backgroundAnim.setRepeatMode(Animation.REVERSE);
backgroundAnim.setInterpolator(new LinearInterpolator());
background.setAnimation(backgroundAnim);
这是我的activity.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rlMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#088A08"
tools:context="com.racsa.UI.MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imgBackMain"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:src="@mipmap/pantalla_principal"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnMain"
android:onClick="goMaps"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lblLoginPopUp"
android:id="@+id/btnOpenLoginOptions"
android:onClick="openLoginOptions"
android:layout_marginBottom="15dp"
android:textColor="#ffffff"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/lblTurismo"
android:id="@+id/lblTurismo"
android:textColor="#ffffff"
android:layout_marginBottom="15dp"
android:layout_above="@+id/btnOpenLoginOptions"
android:layout_centerHorizontal="true" />
</RelativeLayout>
这就是我现在的活动的样子(我一直在尝试使用 setScaleType 方法,不要怪我哈哈)
不管是自动完成还是我必须自己滚动,我只是想让它看起来和表现得像 android 主屏幕背景。我也尝试将图像作为相对布局的背景,但没有成功
提前致谢!
编辑
在尝试将 Sprockets 添加到我的项目后,我在 v4.view.ViewPager 中遇到了一个恼人的 Class not found 错误,我真的开始对此感到困惑。
这是我在项目的 Gradle 文件中的依赖模块:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:22.1.+'
compile 'com.google.code.gson:gson:2.2.4'
// Google Play Services
compile 'com.google.android.gms:play-services:6.5.87'
// Facebook
compile 'com.facebook.android:facebook-android-sdk:4.0.1'
compile 'net.sf.sprockets:sprockets-android:2.4.0'
}
我该如何解决这个问题?
【问题讨论】:
-
iadd
android:scaleType="fitXY"到ImageView -
如果我这样做,它适合,但图像会被拉伸,看起来不太好:/
-
比参考this link