0
我有一個具有導航抽屜的MainActivity。我在導航抽屜中爲每個項目創建了一個片段。我有一個包含在我的content.xml中的toolbar.xml,我想將我的content.xml設置爲我的片段的默認佈局。但我想讓它滾動,因爲我的一些片段有很多文字&圖片! 我該怎麼做?使可滾動的佈局和使用此佈局的片段
這是我MainActivity.java:
public class MainActivity extends AppCompatActivity {
private DrawerLayout drawerLayout;
private Toolbar toolbar;
NavigationView navigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
drawerLayout = (DrawerLayout) findViewById(R.id.a1);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_more_vert_24dp);
navigationView = (NavigationView) findViewById(R.id.a2);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
item.setChecked(true);
drawerLayout.closeDrawer(Gravity.RIGHT);
int id = item.getItemId();
if (id == R.id.intro) {
IntroFragment introFragment = new IntroFragment();
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction().replace(R.id.layout_for_fragment, introFragment).commit();
}
return false;
}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.khat) {
if (drawerLayout.isDrawerOpen(Gravity.RIGHT)) {
drawerLayout.closeDrawer(Gravity.RIGHT);
}
else {
drawerLayout.openDrawer(Gravity.RIGHT);
}
return super.onOptionsItemSelected(item);
}
else {
Toast.makeText(getApplicationContext(), "Something", Toast.LENGTH_LONG).show();
}
return true;
}
public void onBackPressed(){
if (drawerLayout.isDrawerOpen(Gravity.RIGHT)){
drawerLayout.closeDrawer(Gravity.RIGHT);
}else {super.onBackPressed();}
}
}
這是我的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>
我不知道該怎麼做。 我可以這樣做嗎?如果是的話,怎麼樣?
現在發生了什麼問題?你有你的滾動視圖內應該是 –
@DreamersOrg我的佈局不滾動 – Arshiiia13