【发布时间】:2014-08-12 05:02:32
【问题描述】:
我想让我的第一页背景淡出然后转到下一页。 我用渐变制作形状并将其用作第一页的背景。 但是当我在 genymotion 中运行我的应用程序时,第一页的背景颜色是深灰色,我是 Android 开发的新手,所以我不知道如何处理它。 XML:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:centerX="20%"
android:endColor="#aed36c"
android:startColor="#44c8f5" />
</shape>
MAINACTIVITY XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/linergradiant"
android:id="@+id/firstpage"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/texture" >
<LinearLayout
android:layout_width="200dip"
android:layout_height="200dip"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="116dp"
android:background="@drawable/logo_big2" >
</LinearLayout>
</RelativeLayout>
</LinearLayout>
MAINACTIVITY JAVA
public class MainActivity extends ActionBarActivity {
LinearLayout screen;
Handler handler = new Handler();
int i;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
screen=(LinearLayout) findViewById(R.id.firstpage);
(new Thread(){
@Override
public void run(){
for(i=0; i<255; i=i+3){
handler.post(new Runnable(){
public void run(){
screen.setBackgroundColor(Color.argb(255, i, i, i));
}
});
try{ sleep(100); }
catch(Exception e){ break; }
}
startActivity(new Intent(getApplicationContext(),BMIcalculator.class));
}
}).start();
}
}
谁能帮帮我?可以用transition解决吗??
【问题讨论】:
-
mimi,你的意思是,你想要渐变背景什么时候会显示动画淡入淡出,对吧?
-
@pratik 我想要渐变背景,然后淡出并带动画进入第二页。
-
然后在你的 for 循环之后调用 startactivity 就可以了。执行完 for 循环后,接下来要做的就是启动一个活动
-
@mimi 那你为什么不使用淡出动画呢?这将是最简单的方法。
-
@pratik 我试着用动画来写,但我不知道怎么做。我试试这个 [stackoverflow.com/questions/20701127/… 但它对我没有帮助。
标签: java android gradient fade shape