图像未在viewpager和recyclerview中膨胀

时间:2017-05-20 07:27:07

标签: android android-viewpager

我的图片没有显示在viewpager中,我的xml顶部有viewpager,底部是recyclelerview。

enter image description here

我不知道是否需要使用接口实现。我在Android Studio Tutorial - 70 - Implement Swipe Views

处按照此处的图片滑块示例进行操作
public class Home_activity extends BaseActivity {

ViewPager viewPager;

TextView testview;
private static final String urlHome = 
"http://www.androidbegin.com/tutorial/jsonparsetutorial.txt";
private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;

private List<ListItem> listItems;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    viewPager = (ViewPager) findViewById(R.id.viewPager);
    SwipeAdapter swipeAdapter = new 
    SwipeAdapter(getSupportFragmentManager());
    viewPager.setAdapter(swipeAdapter);

    recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    listItems = new ArrayList<>();
    loadRecyclerViewData();
}


<--- PageFagment.java--->

import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class PageFragment extends Fragment {

public PageFragment() {
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup 
container, Bundle savedInstanceState) {

    TextView textView;

    View view = inflater.inflate(R.layout.image_fragment_layout, container, 
false);
    textView = (TextView) view.findViewById(R.id.textViewFragment);
    Bundle bundle = getArguments();
    final String message = Integer.toString(bundle.getInt("count "));
    textView.setText("This id the " + message);

    return view;
}
}



<--- SwipeAdapter.java--->

import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class SwipeAdapter extends FragmentPagerAdapter {

public SwipeAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public android.support.v4.app.Fragment getItem(int i) {
    Fragment fragment = new Fragment();
    Bundle bundle = new Bundle();
    bundle.putInt("count ", i + 1);
    fragment.setArguments(bundle);

    return fragment;
}

@Override
public int getCount() {
    return 3;
}
}

这是xml

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="9">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="3"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:orientation="vertical">

                    <android.support.v4.view.ViewPager
                        android:id="@+id/viewPager"
                        android:layout_width="match_parent"
                        android:layout_height="150dp" />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/topbuttonlinearLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">

                    <Button
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="btn1" />

                    <Button
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="btn1" />

                    <Button
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="btn1" />
                </LinearLayout>
            </LinearLayout>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/topbuttonlinearLayout"
                android:layout_weight="7">
</android.support.v7.widget.RecyclerView>

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</FrameLayout>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1">

    <include layout="@layout/bottom_navigation_layout" />
</FrameLayout>
</LinearLayout>

0 个答案:

没有答案