我设计了Android应用的个人资料页面。但是,当我点击此页面时,它会强制关闭。我怎样才能防止崩溃?
RES /布局/ fragment_profile_vp.xml
<FrameLayout 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"
tools:context="com.example.ray.myoufd.Profile_vp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/header_cover_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="@drawable/profilebg" />
<ImageButton
android:id="@+id/user_profile_photo"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_below="@+id/header_cover_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="-60dp"
android:elevation="5dp"
android:scaleType="centerCrop"
android:src="@drawable/defaultpropic" />
<RelativeLayout
android:id="@+id/profile_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header_cover_image"
android:background="@color/grey"
android:elevation="4dp"
android:paddingBottom="24dp">
<TextView
android:id="@+id/user_profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:text="Name"
android:textColor="#fff"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/user_profile_short_bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/user_profile_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:text="profile short bio"
android:textColor="#fff"
android:textSize="14sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/profile_layout"
android:layout_marginTop="0dp"
android:orientation="horizontal"
android:id="@+id/linearLayout1"
android:background="@color/white">
<TextView
android:layout_height="wrap_content"
android:text="Name:"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="@color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="@color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/profile_layout"
android:layout_marginTop="43dp"
android:orientation="horizontal"
android:id="@+id/linearLayout2"
android:background="@color/white">
<TextView
android:layout_height="wrap_content"
android:text="Gender:"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="@color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="@color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/profile_layout"
android:layout_marginTop="86dp"
android:orientation="horizontal"
android:id="@+id/linearLayout3"
android:background="@color/white" >
<TextView
android:layout_height="wrap_content"
android:text="Email:"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="@color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="@color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/profile_layout"
android:layout_marginTop="129dp"
android:orientation="horizontal"
android:id="@+id/linearLayout4"
android:background="@color/white">
<TextView
android:layout_height="wrap_content"
android:text="Date o birth:"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="@color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="@color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/profile_layout"
android:layout_marginTop="172dp"
android:orientation="vertical"
android:id="@+id/linearLayout5"
android:background="@color/white">
<TextView
android:layout_height="wrap_content"
android:text="Message to friend"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="@color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="@color/black"/>
</LinearLayout>
<Button
android:text="Logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_marginStart="115dp"
android:layout_marginLeft="115dp"
android:background="@color/green"
android:layout_marginTop="605dp" />
<Button
android:text="Save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:layout_marginTop="605dp"
android:layout_marginLeft="210dp"
android:layout_marginStart="210dp"
android:background="@color/green"
/>
</RelativeLayout>
</ScrollView>
</FrameLayout>
的java / com.example.ray.myoufd / Profile_vp.java
package com.example.ray.myoufd;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Profile_vp extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_profile_vp, container, false);
}
}
的java / com.example.ray.myoufd / MainPage.java
package com.example.ray.myoufd;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import com.gigamole.navigationtabbar.ntb.NavigationTabBar;
import java.util.ArrayList;
import java.util.List;
public class MainPage extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_page);
initUI();
}
private void initUI() {
final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb);
final String[] colors = getResources().getStringArray(R.array.default_preview);
final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_horizontal);
final ArrayList<NavigationTabBar.Model> models = new ArrayList<>();
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.home),
Color.parseColor(colors[0]))
.title("Home")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.search),
Color.parseColor(colors[1]))
.title("Search")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.friend),
Color.parseColor(colors[2])).
badgeTitle("123")
.title("Friend")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.personal),
Color.parseColor(colors[3]))
.title("Profile")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.chat),
Color.parseColor(colors[4]))
.title("Discuss")
.build()
);
navigationTabBar.setModels(models);
Search_vp search_Vp = new Search_vp();
Home_vp home_vp = new Home_vp();
Friend_vp friend_vp =new Friend_vp();
Discuss_vp discuss_vp = new Discuss_vp();
Profile_vp profile_vp = new Profile_vp();
List<Fragment> fragmentList = new ArrayList<>();
fragmentList.add(home_vp);
fragmentList.add(search_Vp);
fragmentList.add(friend_vp);
fragmentList.add(profile_vp);
fragmentList.add(discuss_vp);
FragmentPageAdapter fragmentPageAdapter =new FragmentPageAdapter(getSupportFragmentManager(),fragmentList);
viewPager.setAdapter(fragmentPageAdapter);
navigationTabBar.setViewPager(viewPager, 0);
navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) {
}
@Override
public void onPageSelected(final int position) {
navigationTabBar.getModels().get(position).hideBadge();
}
@Override
public void onPageScrollStateChanged(final int state) {
}
});
navigationTabBar.postDelayed(new Runnable() {
@Override
public void run() {
for (int i = 0; i < navigationTabBar.getModels().size(); i++) {
final NavigationTabBar.Model model = navigationTabBar.getModels().get(i);
navigationTabBar.postDelayed(new Runnable() {
@Override
public void run() {
model.showBadge();
}
}, i * 100);
}
}
}, 500);
}
}