3

私は自分のアプリの一部を操作していますが、ユーザーが残りを表示できる[もっと見る]ボタンをクリックする前にテキストコンテンツをピークにできるように、スライドドロワーを完全に閉じるのではなく部分的に開くことができるかどうか疑問に思いました。テキストの。

前もって感謝します。

4

4 に答える 4

8

同様の問題があり、ドロワーが折りたたまれたり閉じられたりしたときにコンテンツの一部を表示できるように SlidingDrawer を変更することになりました。SemiClosedSlidingDrawerでは、ディメンション属性 ' semiClosedContentSize ' を使用して、折りたたんだ/閉じたモードで表示するコンテンツ画面の量を指定します。

<se.smartrefill.view.SemiClosedSlidingDrawer 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:custom="http://schemas.android.com/apk/res/se.smartrefill.app.x"
    android:id="@+id/mySlidingDrawer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    custom:orientation="horizontal"
    custom:handle="@+id/handle"
    custom:content="@+id/content"
    custom:allowSingleTap="true"
    custom:semiClosedContentSize="40dp"
    >

次に、attrs.xml (res/values/ 内) にも以下を含める必要があります。

<declare-styleable name="SemiClosedSlidingDrawer">
    <attr name="handle" format="integer"/>
    <attr name="content" format="integer"/>
    <attr name="orientation" format="string" />
    <attr name="bottomOffset" format="dimension"  />
    <attr name="topOffset" format="dimension"  />
    <attr name="allowSingleTap" format="boolean" />
    <attr name="animateOnClick" format="boolean" />
    <attr name="semiClosedContentSize" format="dimension" />
</declare-styleable>

ここで、「se.smartrefill.app.x」は、AndroidManifest で定義されたアプリケーション パッケージを指します。

この特定の SlidingDrawer (上) は水平方向を使用するように構成されており、コンテンツ ビューの 40 dp 幅 (および fill_parent の高さ) のストリップが折りたたまれた/閉じたモードで (右側に) 表示されます。展開/オープン モードでは、この実装は標準の SlidingDrawer と同じように機能しますが、折りたたみ/クローズ モードでは、コンテンツ画面が完全に非表示になることはありません (標準の SlidingDrawer に変換する semiClosedContentSize="0dp" を指定しない限り)。この実装は、Android-4 (「1.6」) の SlidingDrawer の実装に基づいていますが、Android-14 (「4.0」を含む) まで互換性があります。この実装は、Android の将来のバージョンとも互換性があるはずです (SlidingDrawer では、API 4 と API 14 の間でほとんど何も変更されていません)。

やってみて!

よろしく、ジェイコブ

于 2012-04-02T12:58:33.613 に答える
2

私はあなたと同様の問題に遭遇しました。最初は、スライド ドロワーに (かなり狭い) リスト ビューのみが必要なので、ユーザーはコンテンツを一目で確認できます。ドロワーは、リストのアイテムが選択され、そのアイテムの一部のコンテンツがリスト ビューの横のイメージ ビューに表示されている場合にのみ、完全に開く必要があります。

したがって、私の引き出しのレイアウトは次のようになります。

<RelativeLayout
  android:id="@+id/drawerContainer"
  android:layout_alignParentRight="true"
  android:layout_width="120dp"
  android:layout_height="match_parent">
  <SlidingDrawer
    android:id="@+id/drawer"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:handle="@+id/handle"
    android:content="@+id/content">
    <ImageView
      android:id="@+id/handle"
      android:layout_width="20dip"
      android:layout_height="match_parent"
      android:src="@drawable/drawer_handle />
    <LinearLayout
      android:id="@+id/content"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:orientation="horizontal">
      <ListView
        android:id="@+id/list"
        android:layout_width="100dp"
        android:layout_height="match_parent">
      </ListView>
      <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone">
      </ImageView>
    </LinearLayout>
  </SlidingDrawer> 
</RelativeLayout>

そのため、開始時に画像ビューはなくなりました。リスト ビューの OnItemClickListener で、ドロワーのレイアウト パラメータを制御します。

private OnItemClickListener onItemClickListener = new OnItemClickListener() {

  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {     

    if (imageView.getVisibility() == View.GONE) {     
      ExpandViewAnimation animation = new ExpandViewAnimation(drawerContainer, ((View) drawerContainer.getParent()).getWidth());
      animation.setDuration(500);
      drawerContainer.setAnimation(animation);
      animation.start();
      imageView.setVisibility(View.VISIBLE);
    }
    //code for displaying an image in the imageview
  }  
};

ご覧のとおり、スライド ドロワーを開く際の機能が保持されるように、ドロワー コンテナーにカスタム アニメーションを使用しています。アニメーションクラスは次のとおりです。

public class ExpandViewAnimation extends Animation {
  int targetWidth;
  int initialWidth;
  View view;

  public ExpandViewAnimation(View view, int targetWidth) {
    this.view = view;
    this.targetWidth = targetWidth;
    initialWidth = view.getWidth();
  }

  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {

    int newWidth = initialWidth + (int) ((targetWidth - initialWidth) * interpolatedTime);

    LayoutParams lp = new LayoutParams((LayoutParams) view.getLayoutParams());
    lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    view.setLayoutParams(lp);

    view.getLayoutParams().width = newWidth;
    view.requestLayout();

    if (newWidth == targetWidth) {
      LayoutParams matchParentParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      view.setLayoutParams(matchParentParams);
      view.clearAnimation();
    }
  }

  @Override
  public void initialize(int width, int height, int parentWidth, int parentHeight) {
    super.initialize(width, height, parentWidth, parentHeight);
  }

  @Override
  public boolean willChangeBounds() {
    return true;
  }
}

新しいレイアウト パラメータを設定する理由は、最初にパラメータの初期セットを (レイアウト ファイルのように) 保存し、それを onDrawerClose に適用するためです。

private OnDrawerCloseListener onDrawerCloseListener = new OnDrawerCloseListener() {

  @Override
  public void onDrawerClosed() {
    imageView.setVisibility(View.GONE);
    imageView.setImageDrawable(null);  
    drawerContainer.setLayoutParams(initialLayoutParams);  
  }
};

ユーザーがハンドルをスワイプして引き出しを完全に開けるようにしたい場合は、onTouchListener で同様のアニメーションを適用できます。

最後のコメント: 私のスライド式引き出しは、いくつかの場所で引き出しにアクセスできるように、そのレイアウトに含まれているため、レイアウト内にあります。一般に、引き出しの周りにそのレイアウトは必要ありません。

于 2012-04-23T10:14:04.543 に答える
0

私は最近、あなたが必要とするものとして要件を持っていたアプリを開発しました。グーグルで調べたところ、元の Sliding Drawer のソース コードを変更したことがわかりました。変更したコード全体は、私がテストしたものであり、正常に動作しています。 ファイル全体を送信できます。メール ID を教えてください。
このコードを使用するプロジェクトの値フォルダーにも attrs.xml が必要です。attrs.xml コードは以下に掲載されています。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="SlidingDrawer">
        <attr name="handle" format="integer"/>
        <attr name="content" format="integer"/>
    </declare-styleable>
</resources>

これがお役に立てば幸いです。

于 2011-11-11T07:57:14.297 に答える
0

スライドドロワーの内部コンテンツを次のように設定するようなものを試してみてください

 <SlidingDrawer android:layout_height="wrap_content"
             android:handle="@+id/handle" 
             android:content="@+id/content"
             android:id="@+id/slide" 
             android:orientation="vertical"
             android:layout_width="fill_parent">
    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"...>
       <Button android:id="@+id/ShowMore"... />
       <LinearLayout android:id="@+id/More" android:visibility="gone" ...>
           ... more stuff
       </LinearLayout>

    </LinearLayout>
</SlidingDrawer>

次に、ボタン ShowMore を設定して、線形レイアウト「More」の可視性を View.GONE と View.VISIBLE の間で切り替えます。

**編集:うーん、あなたの質問を読み直して、私は実際には少し混乱しています.タイトルは「..開始時に開かれています」ですが、「部分的に開く」と言います。部分的に開いた状態で起動したかったのですか? またはユーザーがドラッグしたときに部分的に開きますか? 私の提案 (未テスト) は、スライド ドロワーをコンテンツに合わせてサイズをラップし、最初はコンテンツを小さくして、ボタンと「その他」の内側の線形レイアウトの外側に表示したいものだけを表示することです。ボタンをクリックします。

于 2011-06-07T02:00:30.520 に答える