English 中文(简体)
如何在压力 but子时去做下一个布局(而不是活动)?
原标题:How to go to next layout(not activity) when pressed button?

I want to create the instruction, so when user press the next button I want to set to the next layout page. I tried setContentView(R.layout.aboutus); but it looks like to set the new layout to particular page.

Layout:

 <?xml version="1.0" encoding="UTF-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:background="#dddddd">
        <LinearLayout android:gravity="center" android:background = "@drawable/aboutus"
            android:orientation="vertical" android:layout_height="wrap_content"
            android:layout_width="wrap_content"/>
    </LinearLayout>

<code:

 public void onItemClick(AdapterView<?> parent, View view, int position,
                long lg) {
            switch (position) {

            case 4:
                setContentView(R.layout.aboutus);
            }

        }

因此,我想知道,如果没有新的活动,如何进入下一个布局,并可以回过上页。 谢谢。

最佳回答

You should use a ViewFlipper.

参考《观点》:

ViewFlipper myViewFlipper = (ViewFlipper) findViewById(R.id.my_viewFlipper);

之后,你将每一页放在一起,以便:

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.your_layout_id, null);

之后,在《观点》中加入:

myViewFlipper.addView( view );

然后,当用户用下页打到纽顿时,你便使用这种方法:

myViewFlipper.showNext();

或者如果你想要上页的话:

myViewFlipper.showPrevious();
问题回答

使用方言或方言。

You can try to place the same page in your layout and set all it s component to have Visibility.GONE set, and when you press the button, to set all your visible widgets to GONE and others to Visible. Or you can try a dynamically inflate procedure ( to inflate your views ) since you can use separate layout to inflate views. Check this for more information about inflate http://developer.android.com/reference/android/view/LayoutInflater.html

您可以这样做:

如果你有两种不同的布局,一种是一次性的。

首先采用<代码>findviewbyid方法获得每部布局的贴现。

然后使用

    firstlayout.setVisibility(View.VISIBLE).
     secondlayout.setVisibility(View.GONE);

显示第一种布局。

当你报章时,点击的听众会发表

     firstlayout.setVisibility(View.GONE).
     secondlayout.setVisibility(View.VISIBLE);

它虽然运作良好,但布局应当保持。

希望会有所助益。





相关问题
Very basic WPF layout question

How do I get this listbox to be maxiumum size, i.e. fill the group box its in. I ve tried width="auto" Height="auto", width="stretch" Height="stretch" annoyingly at the moment, it dynamicly sizes to ...

How to align the text to top of TextView?

How to align the text to top of a TextView? Equivalent Android API for Swings setInsets()? that is top of text should start be in (0,0) of TextView <?xml version="1.0" encoding="utf-8"?> <...

Centring a flow in Shoes

Can I center the contents of a flow in Shoes? I know that a paragraph can be centred like: para Centred paragrpah , :align=> center However, this does not work with flows: flow(:align=> ...

Overlaying with CSS

I want to load a website in an iframe, and overlay the website with some hints about the website that is shown. However, i got stuck at the point that the website has a variable passive white space at ...

How do you normally make a program look beautiful? [closed]

How can I make an Application look nice and not like an amateur pulled it together? I mean graphic-wise. Is there some sort of book you can read regarding beautiful program layouts, etc? I put this ...

热门标签