Android 如何使用viewpager从TableLayout中的另一个片段调用片段
我想在点击按钮时调用一个片段,它是一个片段。我试过这个代码,但不起作用。当我点击按钮时,这段代码显示下一个片段,但不是它的设计。我只看到一页空白 这是我的主要xml:-Android 如何使用viewpager从TableLayout中的另一个片段调用片段,android,Android,我想在点击按钮时调用一个片段,它是一个片段。我试过这个代码,但不起作用。当我点击按钮时,这段代码显示下一个片段,但不是它的设计。我只看到一页空白 这是我的主要xml:- <LinearLayout android:id="@+id/main_layout" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.an
<LinearLayout
android:id="@+id/main_layout"
android:orientation="vertical"
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=".MainActivity">
<!-- our toolbar -->
<!-- our tablayout to display tabs -->
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabGravity="fill"
android:background="#fa4022"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<!-- View pager to swipe views -->
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"/>
用户配置文件类别代码为:-
public class User_Profile extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rooView=inflater.inflate(R.layout.user_profile, container, false);
return rooView;
}
}
user_profile.xml是:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Profile"
android:textSize="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
如果您可以在单击按钮时看到片段,但未进行设计,则其可能会在您的片段
.xml
文件中出错。通过使用适当的视图可以解决这个问题。如果同一帖子的.xml
文件代码也有问题。您能再给我们看一些数据吗?您试图用什么来替换当前片段的寻呼机片段的XML是什么?
您是否可以检查一下,您所指的是XML文件的布局,而不是单个页面元素?
(因为transaction.replace需要一个片段容器作为它的第一个参数)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Profile"
android:textSize="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>