如何将Gama Carousel的layout_gravity修复为水平中心?

时间:2014-11-04 07:31:53

标签: android carousel android-theme

我在使用Gama的旋转木马框架时遇到问题,因为每次我运行我的Android应用程序时,旋转木马看起来像它的layout_gravity到中心水平不起作用,但是如果我删除了android:theme =" @风格/ AppTheme"在我的清单文件中,轮播现在将被修复,但这不是我的问题的一个很好的解决方案,因为它也将删除我的应用程序的主题。我应该怎么做才能解决这个问题。

这是我的轮播视图的xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.digitalaria.gama.carousel.Carousel
        android:id="@+id/carousel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal"
        android:background="#FFFFFF"/>    
</LinearLayout>

这是我的轮播视图中单个项目/图片的xml文件

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

    <ImageView 
        android:id="@+id/itemImage" 
        android:layout_width="match_parent"    
        android:layout_height="match_parent" />
</FrameLayout>

最后,我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="bzguys.corporation.jaja"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="bzguys.corporation.jaja.CarouselViewActivity"
            android:label="@string/app_name"
            android:screenOrientation="landscape" >
            <intent-filter>
                <action android:name="android.intent.action.DEFAULT" />
                <category android:name="android.intent.category.CAROUSELVIEWACTIVITY" />
            </intent-filter>
        </activity>


    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

试试这个。它可能对你有帮助。

在java文件中添加这些行。首先声明轮播。

Carousel carousel;

设置旋转木马的重力。

carousel.setGravity(Gravity.CENTER_HORIZONTAL);