gpt4 book ai didi

android - 如何更新我的骨架布局代码,使其不会阻止我的viewpager?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:02:27 24 4
gpt4 key购买 nike

我正在尝试将骨架布局/效果添加到viewpager中,但由于某些问题,在我看到一个白色屏幕而不是viewpager数据内容后,会加载闪烁布局。
我正在使用库:

 implementation 'com.ethanhua:skeleton:1.1.2'
implementation 'io.supercharge:shimmerlayout:2.1.0'

这是我的代码:
<android.support.constraint.ConstraintLayout 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:background="@color/white"
android:paddingTop="64dp">
<View
android:id="@+id/roomsTitle"
style="@style/Headline2LeftBlack"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_gravity="center_vertical"
android:background="@color/black_12"
android:text="@string/meeting_rooms"
android:textAppearance="@style/TextAppearance.Text.Chronicle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:paddingBottom="16dp"/>

<View
android:id="@+id/room1"
android:layout_width="match_parent"
android:layout_height="240dp"
android:clipToPadding="false"
android:overScrollMode="never"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:paddingBottom="16dp"
android:background="@color/black_12"
app:layout_constraintTop_toBottomOf="@id/roomsTitle" />


<View
android:id="@+id/room2"
android:layout_width="match_parent"
android:layout_height="240dp"
android:clipToPadding="false"
android:overScrollMode="never"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:background="@color/black_12"
app:layout_constraintTop_toBottomOf="@id/room1" />


</android.support.constraint.ConstraintLayout>

上面的代码是我的骨架视图布局。
下面的代码是活动中的My ViewPager代码:
public class RoomListsActivity extends BaseActivity implements RoomListsMvpView {

@Inject
RoomListsPagerAdapter mPagerAdapter;


@BindView(R.id.room_lists_view_pager)
ViewPager mViewPager;

@BindView(R.id.tab_layout)
TabLayout mTabLayout;

private SkeletonScreen skeletonScreen;

public static Intent getStartIntent(Context context) {
return new Intent(context, RoomListsActivity.class);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_room_lists);

getActivityComponent().inject(this);

setUnBinder(ButterKnife.bind(this));

mPresenter.onAttach(this);

setUp();
}

@Override
protected void setUp() {
setSupportActionBar(mToolbar);

if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_backarrow);
getSupportActionBar().setElevation(0);
getSupportActionBar().setDisplayShowTitleEnabled(false);
}

mViewPager.setAdapter(mPagerAdapter);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mViewPager.setCurrentItem(tab.getPosition());
TextView text = (TextView) tab.getCustomView();
if (text != null) {
text.setTypeface(null, Typeface.BOLD);
text.setTextColor(ContextCompat.getColor(RoomListsActivity.this, R.color.reddish));
}
}

@Override
public void onTabUnselected(TabLayout.Tab tab) {
TextView text = (TextView) tab.getCustomView();
if (text != null) {
text.setTypeface(null, Typeface.NORMAL);
text.setTextColor(ContextCompat.getColor(RoomListsActivity.this, R.color.brownish_grey));
}
}

@Override
public void onTabReselected(TabLayout.Tab tab) { }
});

mRefresh.setOnRefreshListener(this::refreshassistant);

mPresenter.getAvailableRooms();
}


@Override
protected void onDestroy() {
mPresenter.onDetach();
super.onDestroy();
}

@Override
public void showRooms(List<RoomList> roomLists) {
int selectedTab = mTabLayout.getSelectedTabPosition();

mPagerAdapter.setRooms(roomLists);

if (mTabLayout.getTabCount() != roomLists.size()) {
mTabLayout.removeAllTabs();
for (int i = 0; i < roomLists.size(); i++) {
mTabLayout.addTab(mTabLayout.newTab().setText(roomLists.get(i).getRoomTitle()));
}

mViewPager.setOffscreenPageLimit(mTabLayout.getTabCount());

for (int i = 0; i < mTabLayout.getTabCount(); i++) {
TabLayout.Tab tab = mTabLayout.getTabAt(i);
if (tab != null) {
TextView tabTextView = new TextView(this);
tab.setCustomView(tabTextView);
tabTextView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
tabTextView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;

tabTextView.setText(tab.getText());

if (i == 0) {
tabTextView.setTypeface(null, Typeface.BOLD);
tabTextView.setTextColor(ContextCompat.getColor(this, R.color.reddish));
}
}
}

if (selectedTab > 0 && selectedTab < mTabLayout.getTabCount()) {
TabLayout.Tab tab = mTabLayout.getTabAt(selectedTab);
if (tab != null) {
tab.select();
}
}
}
}

@Override
public void showLoading() {
skeletonScreen = Skeleton.bind(mViewPager)
.load(R.layout.item_skeleton_roomlist)
.duration(1000)
.color(R.color.shimmer_color)
.angle(20)
.shimmer(false)
.show();

}

@Override
public void hideLoading() {
super.hideLoading();
skeletonScreen.hide();
mRefresh.setRefreshing(false);
}
}

不知为什么
{
skeletonScreen = Skeleton.bind(mViewPager)
.load(R.layout.item_skeleton_roomlist)
.duration(1000)
.color(R.color.shimmer_color)
.angle(20)
.shimmer(false)
.show();
}

正在重写我的viewpager代码,并显示一个空白的白色屏幕而不是内容。你知道我该怎么解决这个问题吗?
在基类中,我打电话给:
 @Override
public void showLoading() {
hideLoading();
mProgressDialog = CommonUtils.showLoadingDialog(this.getContext());
}

@Override
public void hideLoading() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.cancel();
}
}

最佳答案

我自己解决了这个问题。只需将viewpager添加到framelayout中,出于某种原因,这就成功了。我添加的代码如下:

<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="460dp"
app:layout_constraintTop_toBottomOf="@id/myTitle">

<android.support.v4.view.ViewPager
android:id="@+id/myViewPager"
android:layout_width="match_parent"
android:layout_height="460dp"
android:clipToPadding="false"
android:overScrollMode="never"
android:paddingStart="20dp"
android:paddingTop="16dp"
android:paddingEnd="19dp" />

</FrameLayout>

关于android - 如何更新我的骨架布局代码,使其不会阻止我的viewpager?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56012218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com