PianoView-添加一行代码使用[最美应用]的酷炫控件!

PianoView

English Version

PianoView 能提供一个有趣的类似钢琴键盘的 ViewPager Indicator,即目前最美应用使用的控件。

效果图:

Usage

Dependency

Min SDK:2.3.3

Add Dependency

在项目的 build.gradle 里添加:

dependencies {
    ...
    compile 'com.github.chaossss:PianoView:1.0.1'
}

Customize PianoView

目前还没有提供自定义的特性

Activity

public class MainActivity extends FragmentActivity implements PianoItemListener {
    private PianoView pianoView;
    private List iconUrlList;
    private PianoAdapter pianoAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        iconUrlList = new ArrayList<>();
        pianoView = (PianoView) findViewById(R.id.piano_view);
        pianoView.setScrollPianoStartDelayTime(400);
        pianoView.setPianoItemListenerListener(this);

        fetchData();
        pianoView.showPianoAtPosition(0);
    }

    private void fetchData() {
        for (int i = 0; i < 10; i++) {
            iconUrlList.add("http://img5.duitang.com/uploads/item/201409/07/20140907080946_d4QiL.jpeg");
        }
        pianoAdapter = new PianoAdapter(this, pianoView);
        pianoView.setAdapter(pianoAdapter);
        pianoAdapter.addIconUrlList(iconUrlList);
    }

    @Override
    public void onPianoItemSelected(int itemIndex) {
        Toast.makeText(this, "item " + itemIndex + " selected", Toast.LENGTH_SHORT).show();
        pianoView.showPianoAtPosition(itemIndex);
    }

    @Override
    public void onStartSwipe() {
    }
}

XML


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000">
    <com.github.chaossss.pianoview.PianoView
        android:id="@+id/piano_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>
RelativeLayout>

你可能感兴趣的:(Android,UI,控件,android)