我遇到了android TabLayout的棘手问题
import android.support.design.widget.TabLayout;
Run Code Online (Sandbox Code Playgroud)
当我选择左侧最前面的选项卡,然后向右滚动选项卡并选择右侧最前面的选项卡时,TabLayout首先再次显示左侧选项卡,然后滚动到右侧的选定选项卡.这是我的设置代码
void setupTabs(ViewPager viewPager, TabLayout tabLayout) {
ProductsPagerAdapter adapter = new ProductsPagerAdapter(getChildFragmentManager(), rootCategory.getChildCategories());
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
setStartingSelection(viewPager, adapter);
}
private void setStartingSelection(ViewPager viewPager, ProductsPagerAdapter adapter) {
for(int i = 0 ; i < adapter.getCount(); i++){
String title = (String) adapter.getPageTitle(i);
if(title.equals(selectedCategory.getName())){
viewPager.setCurrentItem(i);
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
和布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/toolbar_color"
app:navigationIcon="@drawable/ic_back_white"
app:title="@string/title_transport"
app:titleTextColor="@color/title_color"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabTextColor="@color/white"
app:tabIndicatorColor="@color/tab_indicator"
app:tabGravity="fill"/> …
Run Code Online (Sandbox Code Playgroud) 我正在尝试RecyclerView
使用不同的列表项来实现.我不知道为什么但是列表项目有一个阴影.当我向上和向下滚动时会出现这个阴影.我想摆脱这个阴影,但没有找到任何可以帮助我的东西.有什么建议?这是我的XML:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.admin.lanet_contactwork.activities.LoginActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="?attr/actionBarSize"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
-------------------------------------- 更新:添加项目布局 - ------ ---------------------
第一个项目布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
>
<TextView
android:id="@+id/divider_txt"
android:layout_width="match_parent"
android:layout_height="48dp"
android:padding="8dp"
android:maxLines="1"
android:textSize="18sp"
android:background="@color/lightgrey"
android:textColor="@android:color/black"
android:textStyle="bold">
</TextView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
第二项项目布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/task"
android:layout_width="match_parent"
android:layout_height="62dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/task_type_img"
android:layout_marginRight="5dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:src="@mipmap/ic_sort_grey" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)