【问题标题】:Make an android activity look and act like android main screen background使一个 android 活动看起来和行为像 android 主屏幕背景
【发布时间】: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

标签: java android


【解决方案1】:

类似this?查看TranslateImagePageChangeListenerSprockets 的一部分(披露:我是开发人员)。

【讨论】:

  • 我在使用 Sprockets 时做得很好(顺便说一句,看起来真的很酷),我收到这个错误说“java 以非零退出值 2 完成”,我无法测试应用程序,我错过了什么吗?
  • 如果您可以重现该错误并且它与库有关,请在 GitHub 上创建一个问题,我会对其进行调查。截图也不错,因为我认为我在使用 Android 应用程序时没有看到过这种错误,并且不确定它会出现在哪里。
  • 感谢您的回复。我实际上修复了错误(实际上是我的错误),现在我正在努力解决一些 ViewPager 识别错误,没什么大不了的......当我真正进入 Sprockets 时,我会告诉你的
  • 嘿伙计!我一直无法进入链轮。 Android Studio 无法与 android 支持一起使用。我将进行完全重新安装以查看最新情况:(
  • 尝试从您的dependencies 中删除support-v4gsonplay-services。 Sprockets 已经包含了所有这些。我听说当依赖项被多次包含时,Android Studio/Gradle 会感到困惑。
猜你喜欢
  • 1970-01-01
  • 2011-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多