当图像从左向右和从右向左移动时,可以看到空白区域

时间:2015-07-05 15:02:12

标签: android xml

当图像从左向右和从右向左移动时,它会离开白色空间。我想要做的是用图像完全填充我的布局,以便动画看起来更好,没有空白区域。

enter image description here

此图片覆盖了此白色区域,因此完整的背景会移动。

MainActivity.java

package com.example.abdul.game;

import android.opengl.Matrix;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;


public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    FrameLayout img_animation = (FrameLayout) findViewById(R.id.img_animation);

    TranslateAnimation animation = new TranslateAnimation(0.0f, 400.0f,
            0.0f, 0.0f);          //  new TranslateAnimation(xFrom,xTo, yFrom,yTo)
    animation.setDuration(7000);  // animation duration
    animation.setRepeatCount(Animation.INFINITE);  // animation repeat count
    animation.setRepeatMode(2);   // repeat animation (left to right, right to left )
//      animation.setFillAfter(true);

    img_animation.startAnimation(animation);  // start animation





}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
}

activity_main.xml中

<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent"
android:layout_height="match_parent"  
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:id="@+id/img_animation"
android:background="@drawable/a"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"  
tools:context=".MainActivity">

<ImageView
android:layout_width="125dp"
android:layout_height="125dp"
android:background="#000"/>

</FrameLayout>

0 个答案:

没有答案