我怎样才能将图标的动画转换为另一个图标,例如箭头(导航抽屉)中的汉堡或十字架(收件箱)中的铅笔?我怎样才能实现这个动画?
我在我的项目中使用导航抽屉,里面有5个片段.在一个片段中,我在设计支持库中引入了TabLayout,其中包括2个片段.一切正常,除非我离开具有TabLayout的片段并切换回它,所有内容都消失了.
在TabLayout的每个片段中,我有一个带有ListView的SwipeRefreshLayout,它们都不会在切换时显示任何内容.
我也注意到TabLayout开始表现得很奇怪.奇怪的是我的意思是白色指示器开始跳跃,你可以把它仍然保持在两个标签的中间......
所以我错过了TabLayout行为如此奇怪的事情吗?
这里的代码:包含TabLayout的片段:
public class MainFragment extends Fragment {
private static String locale;
private static ViewPager viewPager;
private static TabLayout tabLayout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Utils.changeLanguage(getActivity());
final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.MyStyle);
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
View view = localInflater.inflate(R.layout.fragment1, container, false);
viewPager = (ViewPager) view.findViewById(R.id.viewpager);
tabLayout = (TabLayout) view.findViewById(R.id.tabs);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setupViewPager(viewPager);
tabLayout.setupWithViewPager(viewPager);
}
private void setupViewPager(ViewPager viewPager) {
LinesTabsAdapter adapter = …Run Code Online (Sandbox Code Playgroud) android listview android-fragments android-design-library android-tablayout
我注意到TabLayout它只Fragments需要显示一次,所以当我替换Fragment包含TabLayout并切换回它时,它不会重新创建Fragments它保持,因此它们不再显示任何内容.是这样的设计还是我做错了什么?我Fragment在a中使用外部NavigationDrawer,当用户切换到另一个Fragment并返回时,该选项卡Fragments为空,因为它们不会被重新创建.我还注意到在切换回包含它们的片段后,Tabs的行为非常奇怪(它们在跳跃下面的白线,你可以在两个标签之间保持它而不触摸屏幕)
我正在使用的代码:
public class Fragment1 extends Fragment {
private static ViewPager viewPager;
private static TabLayout tabLayout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Utils.changeLanguage(getActivity());
final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.LinesOverlay);
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
View view = localInflater.inflate(R.layout.fragment1, container, false);
viewPager = (ViewPager) view.findViewById(R.id.viewpager);
tabLayout = (TabLayout) view.findViewById(R.id.tabs);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); …Run Code Online (Sandbox Code Playgroud) android android-fragments android-tabs navigation-drawer androiddesignsupport
我注意到,如果CoordinatorLayout内的NestedSCrollView中的内容未填满整个屏幕,则它始终在底部对齐.我该如何解决这个问题?
我的代码:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="140dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_anchorGravity="top|start"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="24dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
card_view:cardBackgroundColor="@color/white"
card_view:cardElevation="2sp"
card_view:cardUseCompatPadding="true">
</android.support.v7.widget.CardView>
<ListView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:divider="@color/black_200"
android:dividerHeight="-7dp"
android:listSelector="@android:color/transparent"
android:cacheColorHint="@android:color/transparent" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/ic_navigate"
android:layout_margin="16dp"
app:backgroundTint="@color/accent_yellow"
app:borderWidth="0dp"
app:elevation="8dp"
app:pressedTranslationZ="12dp"
app:fabSize="normal"
app:rippleColor="@color/accent_dark_yellow"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
如您所见,NestedScrollView中的CardView高200dp,并在底部对齐.
android scrollview android-activity android-cardview android-coordinatorlayout
我希望能够通过使用google places api自动完成一些地方.我只想包括某个地区的某些地方.Googles API文档通过使用该函数来描述此功能setBoundsBias,但我似乎无法使其正常工作,因为它仍然返回指定区域外的结果.
try {
Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
.setBoundsBias(new LatLngBounds(
new LatLng(16.371163, 21.051073),
new LatLng(16.725743, 21.424006)))
.build(getActivity());
startActivityForResult(intent, requestCode);
} catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud) 我注意到当我在xml中使用elevation属性并将其设置为4dp时,我得到一个正常的阴影.当我在java中使用setElevation(4)时,我得到的阴影比xml属性少.我该如何解决这个问题?
有没有办法选择按下游戏服务通知时要启动的活动?它总是将我带到主要活动,即使我已在另一个活动中注册了我的NotificationListener.是否有我需要寻找的额外/捆绑意图?或者是其他东西?
编辑:通过StackOverflow上的另一个问题线程我发现谷歌游戏通知发起的每个意图都包含标志0x14000000.是否可以检查此标志并将用户重定向到实际的多人游戏活动?
android android-intent google-play-services google-play-games
我实现了一个选项来查找距离实际位置最近的标记。我在带有自定义信息窗口的 ClusterItem 中拥有所有标记。在没有集群的普通谷歌地图上,我可以直接使用marker.showInfoWindow();,然后会弹出信息窗口。使用聚类时似乎没有这样的方法,因为标记没有添加为正确的地图标记。
我的代码:
public class StationsFragment extends Fragment implements OnMapReadyCallback {
private static GoogleMap googleMap;
private ClusterManager<MyItem> clusterManager;
private MyItem clickedClusterItem;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.main_activity, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Utils.changeLanguage(getActivity());
final SupportMapFragment map = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
map.getMapAsync(this);
}
@Override
public void onMapReady(final GoogleMap map) {
googleMap = map;
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(0.0, 0.0), 10));
map.setMyLocationEnabled(true);
clusterManager = new ClusterManager<>(getActivity(), map);
map.setOnCameraChangeListener(clusterManager);
map.setOnMarkerClickListener(clusterManager);
map.setInfoWindowAdapter(clusterManager.getMarkerManager());
clusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<MyItem>() …Run Code Online (Sandbox Code Playgroud) 有没有办法在设计支持 TabLayout 中动态更新选项卡的标题?我尝试在 Adapter 中添加一个方法,该方法更改保存选项卡标题的 ArrayList 的内容并通知适配器,但选项卡标题不会更改为新标题。
适配器:
public class TabAdapter extends FragmentPagerAdapter {
private final List<Fragment> fragments = new ArrayList<>();
private final List<String> fragmentTiles = new ArrayList<>();
public TabAdapter(FragmentManager fm) {
super(fm);
}
public void addFragment(Fragment fragment, String title) {
fragments.add(fragment);
fragmentTiles.add(title);
}
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int getCount() {
return fragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return fragmentTiles.get(position);
}
public void setFragmentTiles(int index, String title) {
fragmentTiles.set(index, title);
Log.e("ARRAY", …Run Code Online (Sandbox Code Playgroud) arraylist android-arrayadapter android-design-library androiddesignsupport android-tablayout
有没有办法归档以下内容?我希望我的 RecyclerView 能够在 2 列的网格中显示我的卡片,但我还希望几张卡片具有全屏宽度,而不仅仅是半宽。我尝试使用StaggeredGridLayoutManager存档,但我找不到存档的方法。
我正在寻找有关如何在ListView项目的工具栏中实现上下文菜单的帮助,如WhatsApp所做的那样.到目前为止我发现的唯一教程是关于弹出的对话框,这不是我想要的.有人可以帮助我或提供教程链接吗?谢谢 :)
我在我的项目中使用圆形揭示动画,但它现在正常工作.问题是揭示发生了快速的方式,你几乎看不到揭示因为它立即扩展.我尝试过设置,anim.setDuration()但没有改变任何东西.我使用了谷歌示例中的代码.
这是我的代码:查看myView = getActivity().findViewById(R.id.view_to_expand);
int cx = myView.getRight();
int cy = myView.getBottom();
int finalRadius = Math.max(myView.getWidth(), myView.getHeight());
Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
myView.setVisibility(View.VISIBLE);
anim.start();
Run Code Online (Sandbox Code Playgroud)
view_to_expand是一个简单的相对布局,不要认为问题存在.另外,如何将圆形显示应用于动画过渡?
有没有办法告诉翻译动画始终移动到绝对位置,而不是相对于卡片的位置。据我所知,使用android:toXDelta只会将其移动到相对位置。我希望它从屏幕上的每个点移动到绝对位置(比方说屏幕宽度/2 和屏幕高度/2)。
我的动画:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="1000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="-20%p"
android:toYDelta="-20%p" />
Run Code Online (Sandbox Code Playgroud) android ×12
animation ×2
android-tabs ×1
arraylist ×1
contextmenu ×1
google-maps ×1
icons ×1
listview ×1
menu ×1
scrollview ×1
shadow ×1
view ×1
xml ×1