水平 facebook 样式 silder
Posted
技术标签:
【中文标题】水平 facebook 样式 silder【英文标题】:Horizontal facebook style silder 【发布时间】:2012-06-16 06:18:25 【问题描述】:我最近一直在使用你的 facebook 风格的 android 滑块,我想知道你是否可以帮助我。我需要使滑块从另一侧滑动。所以不是一开始从左向右滑动,我需要它从右向左滑动。
您能解释一下您是如何为我做到这一点的吗?
谢谢
问候, 菲利普
【问题讨论】:
添加有关您正在使用的库的信息会很有帮助。或者添加一些源代码。 【参考方案1】:只需按照以下步骤,
1) 创建一个水平滚动视图。
2) 动态添加两个视图。
3) 使用 Layout Inflater 为两个视图充气。
4)然后将 child 1 设置为初始视图而不是 child 0 ,这样看起来就像从右向左移动而不是从左向右移动。
这里是关于类似 Facebook 的布局的对话。
Layout Animation Android[Facebook]
还有一个,
How to make Facebook's app new menu on Android?
【讨论】:
【参考方案2】:你可以试试这个......
public class AnimateActivity extends Activity
/** Called when the activity is first created. */
private int oldLeft;
private int oldTop;
private int newBottom;
private int newTop;
private int screenHeight;
private int animToPostion;
private Display display;
private boolean menuOpen = true;
private AnimationListener AL;
LinearLayout fakelayout;
LinearLayout bottomlayout;
Button home;
@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
fakelayout=(LinearLayout)findViewById(R.id.fakelayout);
bottomlayout=(LinearLayout)findViewById(R.id.bottomlayout);
home=(Button)findViewById(R.id.home);
display = getWindowManager().getDefaultDisplay();
screenHeight = display.getHeight();
int calcAnimationPosition = (screenHeight /2);
animToPostion = screenHeight - calcAnimationPosition;
newBottom = animToPostion;
if (menuOpen == true)
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,animToPostion);
fakelayout.setLayoutParams(param);
home.setOnClickListener(new OnClickListener()
public void onClick(View v)
// TODO Auto-generated method stub
if(menuOpen)
animslideUp();
menuOpen = false;
else
animSlideDown();
menuOpen = true;
);
// Animation
AL = new AnimationListener()
public void onAnimationEnd(Animation arg0)
// TODO Auto-generated method stub
if (menuOpen == false)
Log.i("onAnimationEnd", "menu is open now");
bottomlayout.layout(0, 0,
bottomlayout.getMeasuredWidth(), bottomlayout.getMeasuredHeight());
else if (menuOpen == true)
fakelayout.setVisibility(View.VISIBLE);
public void onAnimationRepeat(Animation arg0)
// TODO Auto-generated method stub
public void onAnimationStart(Animation arg0)
// TODO Auto-generated method stub
;
public void animslideUp()
fakelayout.setVisibility(View.GONE);
Log.e("in animslideUp", "true");
oldTop=bottomlayout.getTop();
newTop =0;
Log.w("oldTop",""+oldTop);
Log.w("newTop",""+newTop);
TranslateAnimation slideUp = new TranslateAnimation(0, 0, oldTop, newTop);
slideUp.setDuration(500);
slideUp.setFillEnabled(true);
slideUp.setAnimationListener(AL);
bottomlayout.startAnimation(slideUp);
public void animSlideDown()
Log.d("in animslideDown", "true");
oldTop=bottomlayout.getTop();
newTop = animToPostion;
Log.w("oldTop",""+oldTop);
Log.w("newTop",""+newTop);
TranslateAnimation slideDown = new TranslateAnimation(0, 0, oldTop,newTop);
slideDown.setDuration(500);
slideDown.setFillEnabled(true);
slideDown.setAnimationListener(AL);
bottomlayout.startAnimation(slideDown);
XML 是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_
android:orientation="vertical" >
<LinearLayout
android:id="@+id/fakelayout"
android:layout_
android:layout_
android:orientation="vertical"
android:visibility="visible"
</LinearLayout>
<LinearLayout
android:id="@+id/bottomlayout"
android:layout_
android:layout_
android:background="@android:color/white"
android:layout_below="@+id/fakelayout"
android:orientation="vertical" >
<LinearLayout
android:layout_
android:layout_
android:gravity="center"
android:background="@drawable/topbar"
android:orientation="horizontal"
>
<Button
android:id="@+id/home"
android:layout_
android:layout_
android:background="@drawable/home"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
【讨论】:
以上是关于水平 facebook 样式 silder的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Facebook PoP ios 框架水平翻转 UIView?
Swift - 使用 UICollectionViewFlowLayout 的 Facebook 样式图像网格