12

私のアプリには、画像ボタンのあるスライド式の引き出しがあり、クリックすると画像の説明と情報が表示されます。したがって、基本的には、このために 1 つの XML ファイルと 1 つの Java ファイルのみを使用しています。(しかし、表示するイメージボタンとメイジを追加すると、ロードに時間がかかることに気付きました)。そして、API 17 でスライド ドロワーが非推奨になったため、アプリの今後のダウンロードが少し心配になりました。私の質問は、スライド式引き出しやスピナーを使用せずにこれを達成する別の方法があるかどうかです. 画像ごとに xml ファイルと java ファイルを作成したくありません (100 以上の xml ファイルと java ファイルを作成することになります)。

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView 
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">
   <RelativeLayout 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"> 

<ImageView 
    android:id="@+id/iM1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitStart"
    android:adjustViewBounds="true"/>

</RelativeLayout>
</ScrollView>

<SlidingDrawer
    android:id="@+id/sD1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:content="@+id/content"
    android:handle="@+id/handle">

    <Button
        android:id="@+id/handle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/icon_1" />

    <RelativeLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:background="@drawable/icon_background1">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

                <Button
                    android:id="@+id/asample"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/imageicon1"/>
                   .....

そしてJava:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.campsites);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    final SlidingDrawer slider = (SlidingDrawer) findViewById(R.id.sD1);
    final ImageView imageView = (ImageView) findViewById(R.id.iM1);
    slider.animateOpen();

    Button next = (Button) findViewById(R.id.asample);
    Button next1 = (Button) findViewById(R.id.bsample);
    ..........

    next.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            imageView.setImageDrawable(getResources().getDrawable(R.drawable.asample));
            slider.animateClose();
        } 
    });
    next1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            imageView.setImageDrawable(getResources().getDrawable(R.drawable.bsample));
            slider.animateClose();
        } 
    });
    ............

誰かが何をすべきかについて助けたり、提案したりできますか?

4

6 に答える 6

3

これはSlidingDrawer左からですよね?もしそうなら、DrawerLayoutを調べることができます。

これは Android サポート ライブラリの一部であり、XML をこれに置き換えるのはかなり簡単で、API4 との下位互換性があるはずです。

そのページから、例があります。

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>
</android.support.v4.widget.DrawerLayout>

そのページのいくつかのメモ

このレイアウトは、いくつかの重要なレイアウト特性を示しています。

  • メイン コンテンツ ビュー (上記の FrameLayout) は、DrawerLayout の最初の子である必要があります。これは、XML の順序が z オーダーを意味し、ドロワーがコンテンツの上にある必要があるためです。メイン コンテンツ ビューは、ナビゲーション ドロワーが非表示のときに UI 全体を表すため、親ビューの幅と高さに一致するように設定されます。
  • ドロワー ビュー (ListView) は、android:layout_gravity 属性を使用して水平重力を指定する必要があります。右から左 (RTL) の言語をサポートするには、値を「左」ではなく「開始」で指定します (レイアウトが RTL の場合、ドロワーは右側に表示されます)。
  • ドロワー ビューはその幅を dp 単位で指定し、高さは親ビューと一致します。ユーザーが常にメイン コンテンツの一部を表示できるように、引き出しの幅は 320 dp 以下にする必要があります。

ほとんどの違いは、DrawerLayoutがトップ レベルであり、その中に XML を配置することです。したがって、次のようなものです(完全にテストされていません):

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- your content surrounded by a layout to signify that it's actually content -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ScrollView 
           android:layout_width="wrap_content"
           android:layout_height="wrap_content">
           <RelativeLayout 
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"> 

                <ImageView 
                    android:id="@+id/iM1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:scaleType="fitStart"
                    android:adjustViewBounds="true"/>

            </RelativeLayout>
        </ScrollView>
    </RelativeLayout>
    <!-- your sliding menu in its own layout -->
    <LinearLayout 
        android:layout_gravity="start"
        android:layout_width="240dp"
        android:layout_height="wrap_content"> 
        <Button
            android:id="@+id/handle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/icon_1" />

        <RelativeLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent" 
            android:background="@drawable/icon_background1">

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >

                    <Button
                        android:id="@+id/asample"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="@drawable/imageicon1"/>
                       .....
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>
于 2013-08-01T21:01:19.917 に答える
1

これ
は 使用しないAFAIKの良い代替手段でSlidingDrawerあり、引き出しの方向を変更できると思います

于 2013-01-01T02:47:03.090 に答える
1

自分で作成したシンプルなスライド メニューをお勧めします。

私が使ったコンセプト

スライダー ボタンとコンテンツ パネル

最初はスライダーボタンが左にあり(私の例では)、クリックするとシフトし、コンテンツペインが表示されます

どうやってこれを達成したか

私はマージン left で遊んだので、スライダー ボタンを押すと、コンテンツ ペイン (最初は非表示) が screen_width/3 と同じ幅になり、もう一度押すと非表示になります..

ここに私のコードがあります。

public class MainActivity extends Activity  {
    boolean toggle_open=false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
                
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    public void open(View v){
        switch (v.getId()) {
        case R.id.imageButton1:
            if(!toggle_open){
                RelativeLayout header=(RelativeLayout)findViewById(R.id.header);
                Display size=getWindow().getWindowManager().getDefaultDisplay();
                int widthby2=size.getWidth()/3;
                RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
                lp.setMargins(size.getWidth()/2, 0, 0, 0);
                header.setLayoutParams(lp);
            
                RelativeLayout slider=(RelativeLayout)findViewById(R.id.panel);
                slider.setLayoutParams(new RelativeLayout.LayoutParams((size.getWidth()/2),size.getHeight()));
                slider.setVisibility(View.VISIBLE);
            
                toggle_open=true;
            }
            else{
                RelativeLayout header=(RelativeLayout)findViewById(R.id.header);
                RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
                lp.setMargins(0, 0, 0, 0);
                header.setLayoutParams(lp);
                
                RelativeLayout slider=(RelativeLayout)findViewById(R.id.panel);
                slider.setVisibility(View.GONE);
                toggle_open=false;
                    
            }
            break;

        default:
            break;
        }
    }

}

レイアウト XML コード

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <RelativeLayout
        android:id="@+id/header"
        android:background="@android:color/black"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:padding="20dp" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:background="@android:color/black"
            android:onClick="open"
            android:src="@android:drawable/ic_dialog_dialer" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/imageButton1"
            android:layout_toRightOf="@+id/imageButton1"
            android:text="Admin Panel"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@android:color/white" />

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/panel"
        android:visibility="gone"
        android:layout_toLeftOf="@+id/header"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:background="@android:color/darker_gray"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >

        <fragment class="com.example.avanse.FragmentLayout$TitlesFragment"
            android:id="@+id/titles"
            android:layout_width="match_parent" android:layout_height="match_parent"/>

    </RelativeLayout>

</RelativeLayout>
于 2013-08-22T06:09:07.623 に答える
1

アプリUmanoのSlidingUpPanelが今のところ最良の方法のようです. https://github.com/umano/AndroidSlidingUpPanelで見つけることができます。

私はこの他の SOF 投稿でそれに関する情報を見つけました: vertical DrawerLayout または SlidingPaneLayout :D

編集: これも非常に有望に見えます: https://github.com/6wunderkinder/android-sliding-layer-lib (YouTube ビデオでは右から左、左から右に動作するようですが、実際のデモアプリでは、下から上、上から下に移動することも可能であることがわかります)

于 2014-04-24T09:37:48.740 に答える