2017-08-12 32 views
0

我有一个MainActivity与导航抽屉。我为每个项目创建一个片段在我的导航器抽屉中。我有一个包含在我的content.xml中的toolbar.xml,我想将我的content.xml设置为我的片段的默认布局。但我想让它滚动,因为我的一些片段有很多文字&图片! 我在片段布局的Relativelayout中使用Scrollview,但它不起作用。使fragment_layout可滚动

这是我的content.xml中,我想将其设置为我的片段默认布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:id="@+id/layout_for_fragment" 
android:layout_height="match_parent" 
android:background="#132740"> 

<include layout="@layout/toolbar" /> 

</RelativeLayout> 

,这是我IntroFragment.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/colorPrimary" 
tools:context="com.example.arsh.enc.IntroFragment"> 

<ScrollView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<RelativeLayout 
    android:id="@+id/introfragment" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/textView5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="20dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="20dp" 
     android:lineSpacingExtra="10sp" 
     android:text="VERY VERY 
VERY VERY 

VERY VERY 

VERY VERY 

VERY VERY LONG TEXT" 
android:textColor="#FFFFFF" /> 

</RelativeLayout> 
</ScrollView> 


</RelativeLayout> 

正如我所说,我使用ScrollView,但没有结果。谁能告诉我我哪里出错了?我该怎么做才能解决我的问题。

回答

0

采取滚动型的高度和宽度match_parent ...

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 



</ScrollView> 
-2

这是我的片段的.java类---

public class scheduled extends Fragment { 
    private static final String TAG = "MainActivity"; 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.scheduled, container, false); 
     Log.d(TAG, "onCreate: Started."); 
     String []items={"apple","bat","cat","dog","apple","bat","cat","dog","apple","bat","cat","dog"}; 

     ListView lvdata=(ListView)rootView.findViewById(R.id.listview); 
     ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,items); 
     lvdata.setAdapter(adapter); 

     return rootView; 
    } 
} 

你不必添加任何额外的东西,使它滚动。只需添加更多的数据 ,这是我的片段.xml文件---

<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:id="@+id/constraintLayout" 
    android:layout_width="fill_parent" 
    android:gravity="center" 
    android:layout_height="match_parent"> 


    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:id="@+id/listview"/> 
</LinearLayout> 
+0

你是对的就已经是滚动的,但没有必要使用的ListView – godot