我有以下问题:
我正试图从FragmentA 过渡到FragmentB.这些片段之间有一个共享元素,Button以及其他形式View's(参见布局).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:flipper="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mypackage.view.IndicatorViewFlipper
android:transitionGroup="true"
android:id="@+id/intro_viewflipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
flipper:indicatorColor="@color/white"
flipper:indicatorMargin="4dp"
flipper:indicatorRadius="4dp"
flipper:indicatorBarMargin="104dp"/>
<Button
android:id="@+id/account_create_btn"
style="?android:attr/borderlessButtonStyle"
android:textColor="@color/white"
android:layout_width="match_parent"
android:layout_height="@dimen/button_standard_height"
android:layout_above="@+id/txt_already_account"
android:background="@drawable/button_yellow_selector"
android:transitionName="create_account"
android:text="@string/account_create_btn"
android:textSize="24sp"
android:textAllCaps="false" />
<TextView
android:id="@+id/txt_already_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_above="@+id/account_login_btn"
android:layout_marginTop="24dp"
android:text="@string/account_welcome_already_account"/>
<Button
android:id="@+id/account_login_btn"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="@dimen/button_standard_height"
android:layout_marginTop="8dp"
android:layout_alignParentBottom="true"
android:transitionName="login"
android:background="@drawable/button_blue_selector"
android:textColor="@color/white"
android:textSize="24sp"
android:textAllCaps="false"
android:text="@string/account_create_login_btn"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我要做的是让Fragment 除了共享元素之外的所有内容,转换(向左滑动)并让所有内容形成FragmentB,除了共享元素从右边滑入.在此内容转换期间,我希望共享元素保持其原始位置,直到内容转换完成,然后让它滑动到FragmentB中的新位置.
最后一个行为是出错的地方:一旦我在FragmentA中开始退出转换,共享元素就会消失并从右边滑入,内容转换为FragmentB.如果我不添加任何退出,共享元素的行为是正确的/输入过渡.
代码(在FragmentA中):
Fragment …Run Code Online (Sandbox Code Playgroud) 我有以下问题;
我有一个LinearLayout,里面有一个ScrollView,在ScrollView中是一些自定义视图.现在我想在LinearLayout的背景中放置一个图像并保持图像的原始大小.但是当我设置LinearLayout的背景属性时,它会拉伸以适应整个屏幕.如何才能使图像保持原始尺寸?
我的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/some_drawable">
<ScrollView
android:id="@+id/scrollview"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:fillViewport="true">
<some.custom.layout
android:id="@+id/mainLayout"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我正在使用此代码创建InfiniteViewPager:
pAdapter = new InfinitePagerAdapter(new MyPagerAdapter());
InfinitivePAdapter = (InfiniteViewPager) findViewById(R.id.pager);
InfinitivePAdapter.setAdapter(pAdapter);
Run Code Online (Sandbox Code Playgroud)
setCurrentItem()函数似乎有问题.
当我尝试调用setCurrentItem()函数时程序冻结,但不是每次都冻结.该程序仅在以下情况下冻结:setCurrentItem()的项目较低,并且从不同的方法(在我的情况下从onClickListener)调用它.
InfinitivePAdapter.setCurrentItem(7);//item is set on 7
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
InfinitivePAdapter.setCurrentItem(5);//when button is pressed it is set to 5
}
});
Run Code Online (Sandbox Code Playgroud)
然而程序似乎正常工作:物品比前一个更大:
InfinitivePAdapter.setCurrentItem(3);//item is set on 3
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
InfinitivePAdapter.setCurrentItem(12);//when button is pressed it is set to 12
}
});
Run Code Online (Sandbox Code Playgroud)
或者setCurrentItem(3)被一个接一个地调用,即使该项比前一个小:
InfinitivePAdapter.setCurrentItem(7);
InfinitivePAdapter.setCurrentItem(5);
Run Code Online (Sandbox Code Playgroud)
更准确地说,此行中的InfiniteViewPager类中的程序冻结:
@Override
public void setCurrentItem(int item) {
// offset the current item to …Run Code Online (Sandbox Code Playgroud) 我想出来的新RecyclerView联合标准执行LayoutManager的LinearLayoutManager.我的目标是LayoutManager当设备处于纵向时让我的项目水平绘制,并在设备处于横向时垂直绘制它们.为此我在我的活动中使用以下代码onCreate:
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.nextColors);
recyclerView.setAdapter(myAdapter = new MyAdapter(getBaseContext(), myData, myLayout);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
linearLayoutManager.setOrientation(LinearLayout.HORIZONTAL);
} else {
linearLayoutManager.setOrientation(LinearLayout.VERTICAL);
}
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
Run Code Online (Sandbox Code Playgroud)
如果我在设备处于横向或纵向模式时启动活动,则此工作正常.但是,当我在此活动中更改方向时,项目始终水平或垂直绘制,具体取决于首次启动活动时设备的方向.这对我来说没有意义,因为在设备旋转之后,活动被重新创建并且LayoutManager应该采取正确的方向.
有没有人知道如何使setOrientation设备方向更改?