【问题标题】:Nexus 7 layout issue with sliding drawer带有滑动抽屉的 Nexus 7 布局问题
【发布时间】:2012-10-16 16:13:48
【问题描述】:

现在在我的应用程序中,我在屏幕右侧有一个滑动抽屉,用户可以向左拉以查看更多详细信息。问题在于滑动抽屉的“把手”。在所有设备上,它看起来都很棒,而且它应该在哪里。但是,在 Nexus 7 上,右侧有额外的空间。

这是我的布局代码。请帮助确定 Nexus 7 的不同之处。谢谢。

 <com.app.android.apps.app.views.DragContentSlidingDrawer
                   android:id="@+id/drawer"
                   android:layout_width="match_parent"
                   android:layout_height="fill_parent"
                   ancestry:orientation="horizontal"
                   android:layout_alignParentRight="true"
                   ancestry:handle="@+id/panel_slider2"
                   ancestry:content="@+id/panel_frame"
                   ancestry:allowSingleTap="false" >

    <ImageView android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:id="@+id/panel_slider2"
               android:src="@drawable/panel_handle"
               android:scaleType="fitXY"
               android:layout_alignParentRight="true"

            />


    <RelativeLayout android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:gravity="right"
                    android:id="@+id/panel_frame">

        <LinearLayout android:layout_width="fill_parent"
                      android:layout_height="fill_parent"
                      android:gravity="right"
                      android:layout_alignParentBottom="true"
                      android:layout_alignParentRight="true"
                      android:id="@+id/panel_layout">

            <FrameLayout android:layout_height="fill_parent"
                         android:layout_width="fill_parent"
                         android:id="@+id/panel_layout_holder"
                         android:background="@color/background"/>

        </LinearLayout>

    </RelativeLayout>

</com.app.android.apps.app.views.DragContentSlidingDrawer>

【问题讨论】:

  • 你能把你用来加载这个布局的代码贴出来吗?我也不是很清楚截图是什么。中间的深褐色竖条是不是你说的手柄?
  • dokkaebi,该图像是滑动抽屉的屏幕截图。深棕色部分是不需要的空间。实际上,我找到了解决问题的方法。我会发布一个答案。

标签: android android-layout slidingdrawer nexus-7


【解决方案1】:

看来我的帖子不足以解决这个问题。绘制句柄的代码是“Viewgroup”中“dispatchDraw”的重写方法。为了解决这个问题,在那个方法中,我检测手柄位置并使用下面的代码修复它。

 if (mHandle.getLeft() == 0) {
        handle.offsetLeftAndRight(10);
    }

为什么这只会发生在 Nexus 7 上仍然不太合理,但最终,这解决了它。

【讨论】:

    【解决方案2】:

    您似乎在使用 XML 代码时犯了错误。请尝试以下更正:

    <com.app.android.apps.app.views.DragContentSlidingDrawer
                       android:id="@+id/drawer"
                       android:layout_width="**fill_parent**"
                       android:layout_height="fill_parent"
                       ancestry:orientation="horizontal"
                       android:layout_alignParentRight="true"
                       ancestry:handle="@+id/panel_slider2"
                       ancestry:content="@+id/panel_frame"
                       ancestry:allowSingleTap="false" >
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多