Java 动态设置滑动抽屉高度
我想动态或静态地定义滑动抽屉的高度。 下面是我的xml布局文件。如有任何建议,将不胜感激Java 动态设置滑动抽屉高度,java,android,android-layout,android-ui,slidingdrawer,Java,Android,Android Layout,Android Ui,Slidingdrawer,我想动态或静态地定义滑动抽屉的高度。 下面是我的xml布局文件。如有任何建议,将不胜感激 <?xml version="1.0" encoding="utf-8"?> <SlidingDrawer android:layout_width="fill_parent" android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton" android:conten
<?xml version="1.0" encoding="utf-8"?>
<SlidingDrawer android:layout_width="fill_parent"
android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton"
android:content="@+id/contentLayout" android:layout_height="wrap_content">
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/slideHandleButton"
android:background="@drawable/icon_movie"></ImageView>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/contentLayout" android:gravity="center"
android:background="#C0C0C0" android:layout_height="wrap_content">
<Gallery android:id="@+id/gallery" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
<SlidingDrawer android:layout_width="fill_parent"
android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton"
android:content="@+id/contentLayout" android:layout_height="wrap_content">
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/slideHandleButton"
android:background="@drawable/icon_movie"></ImageView>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/contentLayout" android:gravity="center"
android:background="#C0C0C0" android:layout_height="wrap_content">
<Gallery android:id="@+id/gallery" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
您可以将高度设置为特定高度,例如
200dp
,或者如果您想使用wrap\u content
,您可以将高度设置为特定高度,例如200dp
,或者,如果您想使用wrap\u content
只需在xml中的滑动抽屉中设置为pmargin,就可以使用类似这样的内容
<SlidingDrawer android:layout_width="fill_parent"
android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton"
android:content="@+id/contentLayout" android:layout_height="wrap_content">
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/slideHandleButton"
android:background="@drawable/icon_movie"></ImageView>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/contentLayout" android:gravity="center"
android:background="#C0C0C0" android:layout_height="wrap_content">
<Gallery android:id="@+id/gallery" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
android:layout_marginTop="50dip"
只需在xml中的滑动抽屉中设置为pmargin
<SlidingDrawer android:layout_width="fill_parent"
android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton"
android:content="@+id/contentLayout" android:layout_height="wrap_content">
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/slideHandleButton"
android:background="@drawable/icon_movie"></ImageView>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/contentLayout" android:gravity="center"
android:background="#C0C0C0" android:layout_height="wrap_content">
<Gallery android:id="@+id/gallery" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
android:layout_marginTop="50dip"
对SlidingDrawer使用topOffset属性
<SlidingDrawer android:layout_width="fill_parent"
android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton"
android:content="@+id/contentLayout" android:layout_height="wrap_content">
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/slideHandleButton"
android:background="@drawable/icon_movie"></ImageView>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/contentLayout" android:gravity="center"
android:background="#C0C0C0" android:layout_height="wrap_content">
<Gallery android:id="@+id/gallery" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
像这样
<SlidingDrawer android:layout_width="fill_parent"
android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton"
android:content="@+id/contentLayout" android:layout_height="wrap_content">
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/slideHandleButton"
android:background="@drawable/icon_movie"></ImageView>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/contentLayout" android:gravity="center"
android:background="#C0C0C0" android:layout_height="wrap_content">
<Gallery android:id="@+id/gallery" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
<SlidingDrawer
...
android:topOffset="800px"
为滑动抽屉使用topOffset属性
<SlidingDrawer android:layout_width="fill_parent"
android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton"
android:content="@+id/contentLayout" android:layout_height="wrap_content">
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/slideHandleButton"
android:background="@drawable/icon_movie"></ImageView>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/contentLayout" android:gravity="center"
android:background="#C0C0C0" android:layout_height="wrap_content">
<Gallery android:id="@+id/gallery" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
像这样
<SlidingDrawer android:layout_width="fill_parent"
android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton"
android:content="@+id/contentLayout" android:layout_height="wrap_content">
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/slideHandleButton"
android:background="@drawable/icon_movie"></ImageView>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/contentLayout" android:gravity="center"
android:background="#C0C0C0" android:layout_height="wrap_content">
<Gallery android:id="@+id/gallery" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
<SlidingDrawer
...
android:topOffset="800px"
可能重复hey matt的可能重复,我已经尝试将高度设置为200 dp,但效果不太好,当我将layout_height属性设置为200 dp时,滑块只移动到屏幕中央。有什么想法吗?你是说,它不再贴在屏幕底部了?这可能是因为您的FrameLayout没有将其布局高度设置为填充父项,而且您可能必须在您的滑动抽屉上设置android:layout\u gravity=“bottom”。Rhy matt,我已经尝试将高度设置为200 dp,但效果并不理想,当我将布局高度属性设置为200 dp时,滑块只会移动到屏幕中央。有什么想法吗?你是说,它不再贴在屏幕底部了?可能是您的FrameLayout没有将其布局高度设置为填充父对象,而且您可能必须在滑动抽屉上设置android:layout\u gravity=“bottom”