-1

LinearLayoutタイプのいくつかの要素を持つListViewがあります。連絡先のようにスライド効果を出す方法(右側の連絡先がスライドすると電話があり、それ以外の場合はメッセージが書き込まれます)。

4

2 に答える 2

1

リストビューと一緒にビューページャーを使用できます

http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizo​​ntal-view-paging/

于 2012-10-29T09:50:05.960 に答える
0

それはあなたが話しているビューページャーですここに私があなたのために作った例があります

ViewPageExample.javaファイル

public class ViewPageExample extends Activity {

private ViewPager mViewPager;
private Context mContext;
private MyPageAdatper mAdapter;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = this;

mAdapter = new MyPageAdatper();
mViewPager = (ViewPager) findViewById(R.id.mViewPager);
mViewPager.setAdapter(mAdapter);
}

private class MyPageAdatper extends PagerAdapter{


        @Override
        public int getCount() {
               //Since only contacts messages and call logs were mentioned by you
                return 3;
        }


        @Override
        public Object instantiateItem(View collection, int position) {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View mView = null ;
            switch(position){
                case 0:
                    mView   =   inflater.inflate(R.layout.contacts, null);  
                    Button btn1 = (Button) mView.findViewById(R.id.button1);
                    btn1.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Toast.makeText(getApplicationContext(), "Clicked", Toast.LENGTH_SHORT).show();
                        }
                    });
                break;

                case 1:
                    mView   =   inflater.inflate(R.layout.messages, null);   
                break;

                case 2:
                    mView   =   inflater.inflate(R.layout.callogs, null);   
                break;
            }




                ((ViewPager) collection).addView(mView,0);

                return mView;
        }


        @Override
        public void destroyItem(View collection, int position, Object view) {
                ((ViewPager) collection).removeView((View) view);
        }



        @Override
        public boolean isViewFromObject(View view, Object object) {
                return view==((View)object);
        }


        @Override
        public void finishUpdate(View arg0) {}


        @Override
        public void restoreState(Parcelable arg0, ClassLoader arg1) {}

        @Override
        public Parcelable saveState() {
                return null;
        }

        @Override
        public void startUpdate(View arg0) {}

}


}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#a4c639">
<android.support.v4.view.ViewPager
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@+id/mViewPager"/>
</LinearLayout>

callogs.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >


<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Call Logs"
    android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

contacts.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >



<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Contacts"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

</LinearLayout>

messages.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >



<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="SomeMessages"
    android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>
于 2012-10-29T10:03:49.530 に答える