【发布时间】:2018-04-28 12:52:18
【问题描述】:
我正在用片段做这个练习..我如何从我开发的代码中看到..我在 java / layout 文件夹中有两个类 fragment1 和 fragment2。然后是接口的两个.xml文件..现在很难理解为什么这不能正常工作..我必须得到的是:屏幕必须显示两个部分,一个带有脚本“这是片段1”和另一边“这是片段 2”......但这不可见我什至附上了屏幕..如果你有时间和耐心,请查看你的新闻..谢谢,美好的一天:) 片段1.java
package layout;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.test.testfragment.R;
/**
* A simple {@link Fragment} subclass.
*/
public class fragment1 extends Fragment {
public fragment1(){
}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment1,container,false);
}
}
fragment2.java
package layout;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.test.testfragment.R;
/**
* A simple {@link Fragment} subclass.
*/
public class fragment2 extends Fragment {
public fragment2(){
}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment2, container,false);
}
}
fragment1.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:ignore="HardcodedText">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Questo e' il fragment 1"
android:textSize="25sp"/>
</LinearLayout>
fragment2.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00FF00"
tools:ignore="HardcodedText">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Questo e' il fragment 2"
android:textSize="25sp"/>
</LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:baselineAligned="false"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="com.example.test.testfragment.MainActivity">
<fragment
android:id="@+id/fragment1"
android:layout_width="0px"
android:name="layout.fragment1"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="@layout/fragment1" />
<fragment
android:name="layout.fragment2"
android:id="@+id/fragment2"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent" />
</LinearLayout>
【问题讨论】:
-
从几个应用程序清理手机后,我设法通过 Gradle Projects 安装并使用 installDebug .. 现在应用程序看起来像我想要的!谢谢大家!!
标签: java android android-layout android-fragments