sidebar

  • 3 Antworten
  • Letztes Antwortdatum
I

iboshido

Neues Mitglied
0
Hallo leute, ich bräuchte ein sidebar welche aus einer xml datei besteht. Die sidebar soll sich vom oberen rand über meine main_xml schieben, nur habe ich keine ahnung wie das gehen soll xD ich bitte um hilfe :D
 
Ich habe folgenden beitrag zu meinem problem in einem anderen forum gefunden, versteh jedoch nicht wie ich die codes zu benutzten habe.
Der beitrag sah wie folgt aus:

I came up with a solution... I don't know if it is perfect but it is working well.

So what I did was a single FrameLayout with both of the Layouts stacked together and then I just animate the top layout to slide to the right of the screen (just need to call the slideTo or scrollBy. And basically it's that! Quite simple and effective! (the code though is not very pretty :p)

EDIT:

Some code samples.
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFF" >

        <include
        android:id="@+id/menu_layout"
            layout="@layout/menu_list"
            android:visibility="invisible"/>

        <include
            android:id="@+id/news_list_parent"
            layout="@layout/main_news_list"
            />

</FrameLayout>
This is the layout xml, quite simpe. The included .xml are simple LinearLayouts with a heading and a listview.

The "magic" happens in the animation:
Code:
protected void applyTransformation(float interpolatedTime, Transformation t) {
    int newOffset;
    if(expanded) {
        newOffset = 0;
        newOffset = (int)(endOffset*(1-interpolatedTime));
    } else {
        newOffset = (int)(endOffset*(interpolatedTime));
    }
    view.scrollTo(-newOffset, 0);
}
The endOffset is the target movement. I set it before I start the animation, and the View I want to animate (in this case is the view with the id=news_list_parent) it is set on the constructor.

But just to understand how that works make a button and its listener would do something like this:
Code:
if(viewBeneath.getVisibility() == View.INVISIBLE) {
    viewBeneath.setVisibility(View.Visible);
    viewToSlide.slideTo(-(width-50), 0);
}
And finally override the back button to do the opposite of the button
Code:
if(viewBeneath.getVisibility() == View.VISIBLE) {
    viewToSlide.slideTo(0, 0);
    viewBeneath.setVisibility(View.Visible);
}
 
irgendjemand? bitte ? xD
 
der Artikel erklärt im wesentlichen schon , was man machen muss ...

Wie du aber auch weisst, sind das teilweise schnipsel und erklären ja nur den Vorgang.
Also mit past & Copy ist es damit nicht getan.

ABER , da steht schon die Lösung - das Schlüsselwort heisst "Animation"

Um eine Animation zu errechen , musst du eine XML erstellen, die den Vorgang der Animation definiert
(Ausblenden, schieben etc)

Also google mal nach Animationen, dann kommst du deinem Ziel näher



z.b.

Suppose you have an ImageView named imageView and an animation file your_fade_in_anim.xmlinside your res\anim\ folder:

ImageView imageView =(ImageView) findViewById(R.id.imageView);
Animation fadeInAnimation =AnimationUtils.loadAnimation(this, R.anim.your_fade_in_anim);
// Now Set your animation
imageView.startAnimation(fadeInAnimation);
Your XML

<?xml version="1.0" encoding="UTF-8"?>
<setxmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="[duration (in milliseconds)]"
android:repeatCount="infinite"/>
</set>


Quelle : Using fade in animation for a view
 
Zuletzt bearbeitet:
Zurück
Oben Unten