调用的setContentView()多次 [英] Calling setContentView() multiple times

查看:1015
本文介绍了调用的setContentView()多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在一个活动叫的setContentView(ID)多次使用不同的ID来呈现不同的观点还是我绝对要开始一个新的活动?

Is there a way to call setContentView(id) multiple times with different id during one Activity to render different views or do I absolutely have to start a new Activity?

推荐答案

每Austyn的评论,我还是设法找到关于如何使用ViewFlipper做到这一点在另一篇文章的一些指导意见(见上面勾选答案<一个href="http://stackoverflow.com/questions/2666966/how-can-i-make-a-dynamic-flipping-screenlike-that-of-iphone-in-android">here.)

Per Austyn's comment, I did manage to locate some guidance on how to use ViewFlipper to accomplish this in another post (see the checkmarked top answer here.)

如果你不想使用ViewFlipper,我发现了如何在同一视图布局之间切换<一个一个很好的例子href="https://web.archive.org/web/20130413065406/http://www.ceveni.com/2009/07/switching-between-layouts-in-android.html"相对=nofollow>这里:

If you don't want to use ViewFlipper, I found a nice example of how to switch between layouts in the same view here:

XML:

<FrameLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView 
        android:src="@drawable/icon"
        android:scaleType="fitCenter"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"/>
    <TextView
        android:text="Learn-Android.com"
        android:textSize="24sp"
        android:textColor="#000000"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:gravity="center"/>
</FrameLayout>

code:

Code:

private void SwitchLayout2() {
RelativeLayout Layout1 = (RelativeLayout)findViewById(R.id.layout1);
RelativeLayout Layout2 = (RelativeLayout)findViewById(R.id.layout2);

// Enable Layout 2 and Disable Layout 1
Layout1 .setVisibility(View.GONE);
Layout2.setVisibility(View.VISIBLE);
}

private void SwitchLayout1() {
RelativeLayout Layout1 = (RelativeLayout)findViewById(R.id.layout1);
RelativeLayout Layout2 = (RelativeLayout)findViewById(R.id.layout2);

// Enable Layout 1 & Disable Layout2
Layout1.setVisibility(View.VISIBLE);
Layout2.setVisibility(View.GONE);
}

这篇关于调用的setContentView()多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆