我搜索了一些滑动示例,
但我仍然找不到从右向左滑动的例子。
请任何一个给样品项目滑动菜单从右到左
使用此库。。它还具有从右到左的滑动抽屉。。
在活动的onCreate()
中或任何合适的地方,您可以使用以下实现。。
rightDrawer = new DrawerBuilder()
.withActivity(this)
.withDisplayBelowStatusBar(true)
.withSavedInstance(savedInstanceState)
.withDrawerGravity(Gravity.END).append(leftDrawer); // or use build() instead of append()
它将添加从右到左的滑动抽屉...
幻灯片菜单可以使用动画类完成。
声明内部活动:
private LinearLayout slidingPanel;
private boolean isExpanded;
private DisplayMetrics metrics;
//private ListView listView;
private RelativeLayout headerPanel,menuPanel;
private int panelWidth;
private ImageView menuViewButton;
FrameLayout.LayoutParams menuPanelParameters;
FrameLayout.LayoutParams slidingPanelParameters;
LinearLayout.LayoutParams headerPanelParameters ;
LinearLayout.LayoutParams listViewParameters;
//Initialize inside oncreate
metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
panelWidth = (int) ((metrics.widthPixels)*0.45);
headerPanel = (RelativeLayout) findViewById(R.id.header);
headerPanelParameters = (LinearLayout.LayoutParams) headerPanel.getLayoutParams();
headerPanelParameters.width = metrics.widthPixels;
headerPanel.setLayoutParams(headerPanelParameters);
menuPanel = (RelativeLayout) findViewById(R.id.menuPanel);
menuPanelParameters = (FrameLayout.LayoutParams) menuPanel.getLayoutParams();
menuPanelParameters.width = panelWidth;
menuPanel.setLayoutParams(menuPanelParameters);
slidingPanel = (LinearLayout) findViewById(R.id.slidingPanel);
slidingPanelParameters = (FrameLayout.LayoutParams) slidingPanel.getLayoutParams();
slidingPanelParameters.width = metrics.widthPixels;
slidingPanel.setLayoutParams(slidingPanelParameters);
滑动面板:
menuViewButton = (ImageView) findViewById(R.id.menuViewButton);
menuViewButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(!isExpanded){
isExpanded = true;
//Expand
new ExpandAnimation(slidingPanel, panelWidth,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.45f, 0, 0.0f, 0, 0.0f);
//Toast.makeText(getApplicationContext(), "expand", 0).show();
}else{
isExpanded = false;
//Collapse
new CollapseAnimation(slidingPanel,panelWidth,
TranslateAnimation.RELATIVE_TO_SELF, 0.45f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f, 0, 0.0f, 0, 0.0f);
//Toast.makeText(getApplicationContext(), "Collapse", 0).show();
}
}
});
折叠动画类:
public class CollapseAnimation extends TranslateAnimation implements TranslateAnimation.AnimationListener{
private LinearLayout slidingLayout;
int panelWidth;
public CollapseAnimation(LinearLayout layout, int width, int fromXType, float fromXValue, int toXType,
float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) {
super(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
//Initialize
slidingLayout = layout;
panelWidth = width;
setDuration(400);
setFillAfter( false );
setInterpolator(new AccelerateDecelerateInterpolator());
setAnimationListener(this);
//Clear left and right margins
LayoutParams params = (LayoutParams) slidingLayout.getLayoutParams();
params.rightMargin = 0;
params.leftMargin = 0;
slidingLayout.setLayoutParams(params);
slidingLayout.requestLayout();
slidingLayout.startAnimation(this);
//slidingLayout.setBackgroundColor();
//slidingLayout.setBackgroundColor(R.string.white);
}
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
}
展开动画类:
public class ExpandAnimation extends TranslateAnimation implements Animation.AnimationListener{
private LinearLayout slidingLayout;
int panelWidth;
public ExpandAnimation(LinearLayout layout, int width, int fromXType, float fromXValue, int toXType,
float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) {
super(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
//Initialize
slidingLayout = layout;
panelWidth = width;
setDuration(400);
setFillAfter( false );
setInterpolator(new AccelerateDecelerateInterpolator());
setAnimationListener(this);
slidingLayout.startAnimation(this);
//slidingLayout.setBackgroundColor(panelWidth);
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
//Create margin and align left
LayoutParams params = (LayoutParams) slidingLayout.getLayoutParams();
params.leftMargin = panelWidth;
params.gravity = Gravity.LEFT;
slidingLayout.clearAnimation();
slidingLayout.setLayoutParams(params);
slidingLayout.requestLayout();
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
这是xml:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- Menu Panel -->
<RelativeLayout
android:id="@+id/menuPanel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/gray_bg"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="@+id/menu_title_1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="0dp"
android:background="#353535"
android:gravity="center_vertical"
android:paddingLeft="15dp"
android:text="@string/menu_title"
android:textColor="@android:color/white" >
</TextView>
<View
android:id="@+id/menu_item_divider_1"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_below="@+id/menu_title_1"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:background="#b5b5b5" />
<TextView
android:id="@+id/menu_item_1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="@+id/menu_item_divider_1"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:text="@string/korean" >
</TextView>
<View
android:id="@+id/menu_item_divider_2"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_below="@+id/menu_item_1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#b5b5b5" />
<TextView
android:id="@+id/menu_item_2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="@+id/menu_item_divider_2"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:text="@string/english"
>
</TextView>
<!-- Sliding Panel -->
<LinearLayout
android:id="@+id/slidingPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:gravity="left"
android:orientation="vertical" >
<View
android:id="@+id/dividerHeaderBottom"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#414141" />
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@color/whitec" >
<Button
android:id="@+id/buttonback"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignBottom="@+id/buttonperson"
android:layout_alignParentTop="true"
android:layout_marginRight="14dp"
android:layout_toLeftOf="@+id/buttonperson"
android:background="@drawable/back" />
<ImageView
android:id="@+id/menuViewButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginLeft="27dp"
android:layout_toRightOf="@+id/buttonyummy"
android:clickable="true"
android:contentDescription="@string/description"
android:src="@drawable/lin"
android:visibility="visible" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>
package com.slidingmenu.example;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import com.slidingmenu.example.fragments.ColorFragment;
import com.slidingmenu.lib.SlidingMenu;
import com.slidingmenu.lib.SlidingMenu.OnClosedListener;
import com.slidingmenu.lib.SlidingMenu.OnOpenedListener;
public class LeftAndRightActivity extends BaseActivity {
public LeftAndRightActivity() {
super(R.string.left_and_right);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSlidingMenu().setMode(SlidingMenu.LEFT_RIGHT);
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
setContentView(R.layout.content_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, new SampleListFragment())
.commit();
getSlidingMenu().setSecondaryMenu(R.layout.menu_frame_two);
getSlidingMenu().setSecondaryShadowDrawable(R.drawable.shadowright);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.menu_frame_two, new SampleListFragment())
.commit();
}
}
确保得到一个干净和更新的库副本。以防万一。
我试图将一个视图从右向左滑动,点击一个按钮,它的可见性就消失了,点击另一个按钮,它的可见性就消失了。我尝试了以下解决方案。但是它要求视图是可见的,并且它会将视图从一个位置滑动到另一个位置。我想要一个滑动效果,就像那样,但是要有。我怎样才能做到这一点?
我试着让滑动抽屉菜单和脸书应用程序中的一样。我在这里提出了很多像这样的问题。找到了很多库,但它们都在不同的库中从左向右或从右向左滑动。我想让它从两侧滑动,通过顶部栏中的两个按钮从左向右和从右向左滑动。有人能帮我吗。 提前感谢。
问题内容: 我所看到的和jQuery的。左右滑动的功能/方式如何? 问题答案: 您可以使用jQueryUI中的其他效果来执行此操作: 快速示例:
我正在尝试为我的RecolyerView添加滑动功能。我正在跟随这个链接添加刷卡。https://github.com/nikhilpanju/recyclerviewenhanced/blob/master/recyclerviewenhanced/src/main/java/com/nikhilpanju/recyclerviewenhanced/recyclertouchlistener.j
问题内容: 我想做的只是为移动设备添加左/右触摸滑动功能。我怎样才能做到这一点? 另外,如何使显示在悬停时的上一个/下一个按钮变小,以用于移动/ ipad版本? 谢谢 问题答案: 更新: 当我刚接触Web设计时,我想到了此解决方案。既然我年纪大一些又聪明了, 马克·希尔拉迪 ( Mark Shiraldi) 给出的答案似乎是一个更好的选择。参见下一个最佳答案;这是一个更有效率的解决方案。 我最近参
我有viewpager和tablayout,内部viewpager有一个创建RecolyerView片段, 在RecyclerVIew roe项目中,我创建了一个水平滚动视图,用于向左/向右移动, 基本上,我只想滑动屏幕的75%左右,然后显示可滑动视图, 我还使用了的,但它会刷行(100%刷行), 但所有这些都不能正常工作,因为当我们在recyclerview项上滑动时,有时触摸到ViewPage