0

SlidingDrawer に問題があります。その中のすべてのボタンをクリックできませんでした。

SlidingDrawer の xml ファイルは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<SlidingDrawer xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="110dp"
    android:content="@+id/content"
    android:handle="@+id/handle">

    <Button
        android:id="@+id/handle"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:text="@string/menu" />

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_gravity="center"
        >

        <Button
            android:id="@+id/btn_video"
            style="@style/button_menu_bottom"
            android:drawableTop="@drawable/mnu_video"
            android:text="@string/video" />

        ...
        ...

    </LinearLayout>

</SlidingDrawer>

これがSlidingDrawerから拡張された私のJavaファイルです

パッケージcom.example;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.SlidingDrawer;
import com.example.R;

public class BottomMenuBar extends SlidingDrawer {

    private SlidingDrawer mSlidingDrawer;
    private Button mButtonSlidingDrawer;
    private LinearLayout mLayoutContent;
    private Button mButtonVideo;
    private Button mButtonPhoto;
    private Button mButtonChat;
    private Button mButtonSetting;

    public BottomMenuBar2(Context context, AttributeSet attrs) {
        super(context, attrs);
        String infService = Context.LAYOUT_INFLATER_SERVICE;
        LayoutInflater li;
        li = (LayoutInflater) getContext().getSystemService(infService);
        li.inflate(R.layout.bar_bottom_menu, this, true);
        mSlidingDrawer=(SlidingDrawer)findViewById(R.id.sld_bottom_menu);
        mButtonSlidingDrawer=(Button)findViewById(R.id.handle);
        mLayoutContent=(LinearLayout)findViewById(R.id.content);
        mButtonVideo=(Button)findViewById(R.id.btn_video);
        mButtonSetting=(Button)findViewById(R.id.btn_setting);
    }

    public Button getmButtonSlidingDrawer() {
        return mButtonSlidingDrawer;
    }
    public void setmButtonSlidingDrawer(Button mButtonSlidingDrawer) {
        this.mButtonSlidingDrawer = mButtonSlidingDrawer;
    }

    ...
    Setter & Getter methods
    ...     
}

これが私のmain.xmlファイルです:

<?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:background="@drawable/bg_main"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.1" >

        ...
        Any content
        ...

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <com.example.BottomMenuBar
            android:id="@+id/sld_bottom_menu"
            android:layout_width="wrap_content"
            android:layout_height="110dp"
            android:handle="@+id/handle"
            android:content="@+id/content"
            />

    </LinearLayout>

</LinearLayout>
4

2 に答える 2

0

スライド ドロワーのボタンについては、xml でどのメソッドを使用するかを各ボタンに指示しますandroid:onClick

        <Button
            android:id="@+id/sortbutton"
            android:layout_width="0dp"
            android:layout_height="35dp"
            android:layout_weight="1"
            android:onClick="SortClickHandler"
            android:text="@string/sd_sortmethod_button"
            android:textSize="12dp" />

次に、適切なアクティビティでメソッドを定義します。

public void SortClickHandler(View v) {
    //  Do stuff here
}

編集

私はあなたの問題を見つけたと思います。ここの開発者ドキュメントから、それは言います、そして私は引用します:

SlidingDrawer should be used as an overlay inside layouts. This means SlidingDrawer 
should only be used inside of a FrameLayout or a RelativeLayout for instance.

したがって、レイアウトを RelativeLayout に変更すると、ボタンが機能することがわかると思います。スライド ドロワーのすべての使用方法を再確認しましたが、すべての場合において、スライド ドロワーを含むビューのルート要素は RelativeLayout です。

于 2012-05-24T04:44:47.777 に答える
0

延長する理由がわかりませんSlidingDrawer

ここでドキュメントを参照してください。

<SlidingDrawer
 android:id="@+id/drawer"
 android:layout_width="match_parent"
 android:layout_height="match_parent"

 android:handle="@+id/handle"
 android:content="@+id/content">

 <ImageView
     android:id="@id/handle"
     android:layout_width="88dip"
     android:layout_height="44dip" />

 <FrameView
     android:id="@id/content"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
   [INSERT VIEWS HERE]
 <FrameView>

</SlidingDrawer>

では、Activity技術的にオブジェクトにアクセスする必要さえありませんSlidingDrawer(スライド機能は既に標準として配置されており、ビューの in が含まれているだけcontentなので、干渉する必要はありません)。

ビューへのゲイン参照からActivity、[INSERT VIEWS HERE] に追加します。その後、これらの各ボタンで実行できsetOnClickListener()ます。

于 2012-05-24T09:03:25.433 に答える