问题
I want to obtain a similar tab effect with the button bar of twitter app.
I wish to click on a button and change the view down. I can switch activity but I think It's wrong, or not?
The top bar have to be fix like a frame. Like this:
Ok now I post a part of my idea (i found something similar here: http://www.talkandroid.com/android-forums/android-development-answers-tutorials-code-snippets/1515-how-i-open-image-imagebutton.html)
code:
newsButton = (ImageButton) findViewById(R.id.news);
newsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// on click go to the news view (no activity yet)
setContentView(R.layout.news);
}
});
回答1:
Like in the Google IO App?
If so, the Source Code is freely available here.
Okay, a little tour on how Google does it:
- The
activity_home.xml
-layout includes (Line 21) theactionbar.xml
-layout (This is done in every Layout so the Actionbar must not always be duplicated). - The
actionbar.xml
-Layout creates aLinearLayout
for the UI-Elements. - Then, for example the
HomeActivity-Activity sets
the content view to the
activity_home.xml
-layout, receives an ActivityHelper-class and calls itssetupActionBar()
-method. - The mantioned
ActivityHelper
-class is in thehg/ android/ src/ com/ google/ android/ apps/ iosched/ util/
-package and has the setupActionBar()-method which creates the Action bar.
This might be easier then it looks. Read your way through the Source Code and try it yourself.
回答2:
I think these controls are Radio Button/ Radio Group with customization.
来源:https://stackoverflow.com/questions/6533434/button-bar-similar-to-twitter-app-for-android