我希望文本保留在我的页面下方,并且不要随着选项卡式布局和容器中的部分滑动和移动。我正在使用 Android Studio 及其默认的选项卡式活动
如图所示,红色标记的部分被固定并且不会通过滑动移动:
这是代码:
活动主
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="ahmad.saberghadim.tabbed.MainActivity">
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressBar2"
android:layout_marginBottom="80dp"
android:layout_gravity="bottom" /></LinearLayout>
</android.support.design.widget.CoordinatorLayout>
片段主
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="ahmad.saberghadim.tabbed.MainActivity$PlaceholderFragment"
android:id="@+id/rl"
android:background="@drawable/bg_gradientss">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="@drawable/ss" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/section_label_l"
android:layout_alignParentEnd="true"
android:textSize="20sp"
android:textColor="#ffffff"
android:layout_above="@+id/section_label"
android:layout_alignParentRight="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/section_label"
android:textColor="#ffffff"
android:text="Large Text"
android:textSize="15sp"
android:textStyle="bold"
android:singleLine="false"
android:layout_gravity="center"
android:textIsSelectable="true"
android:layout_above="@+id/progressBar"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageView
android:onClick="start"
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/imageView2"
android:src="@drawable/start"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:visibility="gone" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="80dp" />
</RelativeLayout>
主要活动
package ahmad.saberghadim.tabbed;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link FragmentPagerAdapter} derivative, which will keep every
* loaded fragment in memory. If this becomes too memory intensive, it
* may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
private SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
final ProgressBar pb = (ProgressBar) findViewById(R.id.progressBar2);
pb.setProgress(16);
}
public void start (View v){
startActivity(new Intent("ahmad.saberghadim.kums.MainActivity"));
}
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
public PlaceholderFragment() {
}
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
TextView textViewl = (TextView) rootView.findViewById(R.id.section_label_l);
ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
ImageView imageView2 = (ImageView) rootView.findViewById(R.id.imageView2);
RelativeLayout rl = (RelativeLayout) rootView.findViewById(R.id.rl);
if(getArguments().getInt(ARG_SECTION_NUMBER)==1){
imageView2.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.ss);
textViewl.setText("خوش اومدی!");
textView.setText("با این اپ دیگه سرگردون نباش، کافیه دنبال چیزی که می خوای بگردی");
}if(getArguments().getInt(ARG_SECTION_NUMBER)==2){
//pb.setProgress(33);
imageView2.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.sa);
textView.setText("در هر لحظه با این آیکون به صفحه ی شخصی خود در سایت دانشگاه بروید");
}
if(getArguments().getInt(ARG_SECTION_NUMBER)==3){
//pb.setProgress(50);
imageView2.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.sb);
textView.setText("برنامه ی آموزشی خود را بدون نیاز به صرف زمان به راحتی دریافت کنید");
}
if(getArguments().getInt(ARG_SECTION_NUMBER)==4){
//pb.setProgress(66);
imageView2.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.sc);
textView.setText("در بخش تنظیمات به تنظیمات دلخواه خود بپردازید");
}
if(getArguments().getInt(ARG_SECTION_NUMBER)==5){
//pb.setProgress(100);
imageView2.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.sd);
textView.setText("ما را با نظرات خود راهنمایی کنید");
}
if(getArguments().getInt(ARG_SECTION_NUMBER)==6){
//pb.setVisibility(View.GONE);
imageView2.setVisibility(View.VISIBLE);
rl.setBackgroundResource(R.drawable.bg_gradient);
textView.setText("انجمن فضای مجازی و IT دانشگاه علوم پزشکی کرمانشاه");
}
return rootView;
}
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
return PlaceholderFragment.newInstance(position + 1);
}
@Override
public int getCount() {
// Show 6 total pages.
return 6;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "SECTION 1";
case 1:
return "SECTION 2";
case 2:
return "SECTION 3";
case 3:
return "SECTION 4";
case 4:
return "SECTION 5";
}
return null;
}
}
}