大体以下の様な動きをします。

potatotips (iOS/Android開発Tips共有会) 第2回
で発表してきました。potatotips2とは
使い方
まずはレイアウトXMLを作ります。ViewStickerを使うにはFragmeLayoutとScrollViewが必要です。以下の様な感じでScrolViewをFrameLayoutでくるんで、ScrollViewに具を詰めます。
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/description_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
</FrameLayout>
次にActivity( or Fragment )でレイアウトを初期化し、ViewStickerを作成します。ViewSticker#starch()でレイアウトを持つActivity( or Fragment )、ScrollView、FrameLayoutのIDを渡すとインスタンス化できます。
次にstickメソッドでViewを渡すと、そのViewがヘッダ固定されます。複数のViewを登録する事もできます。
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initialize ViewSticker
ViewSticker sticker = ViewSticker
.starch(this, R.id.scroll_view, R.id.container);
//prepare sticky
sticker.stick(findViewById(R.id.description_header));
}
}
おわりに
まだ変な挙動があったり、未実装の機能があったりするし、Android Studio用だし、Maven Centralには登録してないしで色々やる事ありますが、ちょこちょこやろうかと思います。Pull Request大歓迎です!
0 件のコメント:
コメントを投稿