1

2つのxml(フローティングダイアログテーマを使用)に閉じるボタン[x]があり、viewPagerを使用しています。

閉じるボタンは、2つのxmlの右上隅にあります。ただし、左または右にスワイプすると、ボタンも前後にスワイプされ、非常に奇妙に見えます。ページをスワイプしてもボタンを固定したままにするアイデアはありますか?

ページの1つからのコード(両方のページは類似しています):

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minWidth="350dp" 
    android:minHeight="700dp"
    android:background="#CECECE"
    android:id="@+id/dialogLayout"
    android:orientation="vertical">

<TableRow
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

<TextView
    android:id="@+id/lblInfo"
    android:layout_marginLeft="10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="-6dp"
    android:text="Information"
    android:textStyle="bold"
    android:textColor="#000"
    android:textSize="40dp" />

<ImageButton
    android:id="@+id/btnClose"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="320dp"
    android:layout_marginTop="-4dp"
    android:layout_marginRight="-4dp"
    android:background="#0000"
    android:src="@drawable/close" />

</TableRow>

<TextView
    android:id="@+id/lblInfo"
    android:layout_width="wrap_content"
    android:layout_height="400dp"
    android:layout_alignParentRight="true"
    android:layout_marginLeft="10dp"
    android:textColor="#000"
    android:textSize="17dp" />



</LinearLayout>

viewPager xml

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>
4

1 に答える 1

2

最後に、@ Luksprogからのアドバイスに従って、閉じるボタン(btnClose)とページタイトル(lblTitle)をviewPagerの外に配置しました。ページタイトルにonPageChangeListenerを適用すると、閉じるボタンが修正され、TextViewがページめくりに応じてタイトルを変更するようになりました。コード:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.viewpagerbase);

    //add onClickListener for the btnClose
    ImageButton btnClose = (ImageButton)findViewById(R.id.btnClose);
    btnClose.setOnClickListener( new OnClickListener() {
        public void onClick(View v) {
            onBackPressed();
        }
    });


    //attach the viewPage adapter 
    MyPagerAdapter adapter = new MyPagerAdapter();
    ViewPager myPager = (ViewPager) findViewById(R.id.viewPager);
    myPager.setAdapter(adapter);
    myPager.setCurrentItem(0);
    //set listener for page change 
    myPager.setOnPageChangeListener(this);

}   //end of onCreate
于 2012-11-09T02:39:49.353 に答える