我正在工作一个我的应用程序,我想知道是否有可能有一个滑动抽屉部分打开,而不是完全关闭,因此用户可以在点击显示更多按钮之前在文本内容达到峰值这将能够显示文本的其余部分。SlidingDrawer开始半打开
在此先感谢。
我正在工作一个我的应用程序,我想知道是否有可能有一个滑动抽屉部分打开,而不是完全关闭,因此用户可以在点击显示更多按钮之前在文本内容达到峰值这将能够显示文本的其余部分。SlidingDrawer开始半打开
在此先感谢。
也许你可以试试设置的的slidingdrawer的东西的肠子内容,如
<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>
然后设置按钮的相册更多>>暂可切换的LinearLayout“更多” View.GONE和View.VISIBLE之间的可视性
**编辑:嗯重新读你的问题,我实际上有点困惑:标题是“开始打开”,但你说“部分开放”。你是否希望它在部分打开状态下启动?或者在用户拖拽时部分打开?我的建议(未经测试)是让滑动的抽屉将其大小包裹到内容中,并且内容最初开始很小,只显示按钮+无论您想在“更多”内部线性布局外显示,然后显示当他们点击按钮。
我最近开发的应用程序,其中我有要求,你所要求的。 通过谷歌搜索,我发现我们修改原始滑动抽屉的源代码,我做到了这一点, 和整个修改后的代码与我一起测试,我的测试和它的工作正常。 我可以给你发送整个文件。只需给我你的电子邮件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>
我希望这会帮助你。
你会介意在pastbin上发布你的代码并为我们提供网址吗?我需要让SlidingDrawer在活动开始时部分打开。我设法使用android:bottomOffset =“ - 50dip”来解决这个问题,这个问题在于SlidingDrawer将内容的可见性保持在GONE上,直到完全按下或打开句柄。谢谢,蒂亚戈 – Thiago 2012-01-02 12:19:58
嗨,有没有机会看到你的代码?这是我希望集成到我的应用程序中的UI功能,但我无法完全正确地工作,并使用按钮将列表视图设置为全屏显示。运作良好,但现在如何运作会很好。 – 2012-01-17 12:44:27
Hi @Android_Crazy,你介意发布你的代码并发送给我们的网址?我也遇到同样的问题。谢谢 – Thiago 2012-02-20 20:23:01
我有一个类似的问题,我最终修改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 /价值/),还需要包含:
<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(上图)被配置为使用水平方向,内容视图的40dp宽(和fill_parent高)条将在折叠/关闭模式下显示(向右)。在展开/打开模式下,此实现将像标准SlidingDrawer一样工作,但在折叠/关闭模式下,内容屏幕永远不会完全隐藏(除非指定semiClosedContentSize =“0dp”,这会将其变成标准SlidingDrawer)。该实现基于Android-4(“1.6”)中的SlidingDrawer的实现,但与(包括)Android-14(“4.0”)兼容。此实现应该与未来的Android版本兼容(API 4和API 14之间的SlidingDrawer几乎没有任何变化)。该实现支持垂直和水平方向。
试一试吧!
问候, 雅各
非常感谢这个实现,它为我工作!但(我知道我已经晚了一年,但希望它可以帮助其他人阅读这个):在第519行有两个减号( - ),应该有一个。否则,在使用半封闭内容时,点按展开功能将无法使用。 – RemiX 2013-05-27 21:04:46
我是一名iOS开发人员,可以为您提供一个示例项目吗?如果你可以修改这个网站是很好的http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/ – 2015-02-18 05:40:16
我碰到类似的问题就来了,你。在开始时,我只需要在我的滑动抽屉中使用一个(相当窄的)列表视图,这样用户就可以在内容中找到一个顶点。只有当列表中的项目被选中并且该项目的某些内容显示在列表视图旁边的图像视图中时,抽屉才应完全打开。
因此我抽屉里的布局是这样的:
<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
}
};
正如你可以看到我用我的自定义动画的抽屉容器,使得开口滑动抽屉的nicity被保留。这里的动画类:
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中应用类似的动画。
最后的评论:我的滑动抽屉处于布局中,因为它被包含在该布局中,因此抽屉可以在多个位置访问。一般来说,你不需要抽屉周围的布局。
我试图实现的是部分文本显示在所有时间直到用户点击按钮显示更多然后文本扩展和内容完全显示。这足够清楚了吗? – 2011-06-07 17:31:57
所以或许a)有一个textview和按钮更简单。最初给文本视图一个删节的文本,直到他们点击更多的按钮,然后给它的全文或b)有一个删节的文本视图,按钮和一个隐藏的文本与全文,当他们点击按钮隐藏文本视图显示? – jkhouw1 2011-06-07 18:16:23
我试过这个潜在的解决方案,但它似乎不工作。 – 2011-06-07 18:18:10