我是一名Android开发的新手,同时我正在学习密码学入门课程,所以我决定将两者结合起来制作这个应用程序。我使用TabLayout为每种加密方法(RSA和XOR)创建一个选项卡,并为说明和帮助创建了一个选项卡。一切都进行得很顺利,直到我在帮助选项卡中添加了一个ScrollView来显示说明。但是ScrollView无法滚动,我不知道原因,我已经在网上寻找帮助并尝试了所有可能的解决方案,例如更改ScrollView属性的宽度和高度等,但我卡住了,请你帮帮我好吗?
截图
-----编辑 3/02/16-----
**我的main_activity.xml**
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.usuario.chatparritos.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
app:tabMode="fixed"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"
tools:context="net.voidynullness.android.tabitytabs.TabLayoutActivity"
android:background="#ffffff"/>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_info"/>
</android.support.design.widget.CoordinatorLayout>
-----//编辑 3/02/16-----
这是我的tab_fragment_3.xml文件
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:focusableInTouchMode="true"
android:focusable="true"
android:scrollbars="vertical"
android:id="@id/scrollView">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#FFFFFF"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="left">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_chatparritos"
android:textSize="20dp"
android:layout_marginTop="15dp"
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/body_chatparritos"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
android:layout_marginTop="9dp"
android:background="@drawable/blue_cornered_textview"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/link_khan"
android:layout_marginTop="-19dp"
android:textAppearance="@style/TextAppearance.Design.Hint"
android:textSize="15dp"
android:linksClickable="true"
android:id="@+id/linkAcademy"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_xor"
android:textSize="20dp"
android:layout_marginTop="25dp"
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/body_xor"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
android:layout_marginTop="9dp"
android:background="@drawable/blue_cornered_textview"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/instructions_xor"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
android:layout_marginTop="15dp"
android:background="@drawable/yellow_cornered_textview"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_rsa"
android:textSize="20dp"
android:layout_marginTop="25dp"
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/body_rsa"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
android:layout_marginTop="9dp"
android:background="@drawable/blue_cornered_textview"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/link_rsa"
android:layout_marginTop="-19dp"
android:textAppearance="@style/TextAppearance.Design.Hint"
android:textSize="15dp"
android:linksClickable="true"
android:id="@+id/linkRSA"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/instructions_rsa"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
android:layout_marginTop="15dp"
android:background="@drawable/yellow_cornered_textview"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_numeros"
android:textSize="20dp"
android:layout_marginTop="25dp"
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/body_numeros"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
android:layout_marginTop="9dp"
android:background="@drawable/blue_cornered_textview"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/nota"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:background="@drawable/red_cornered_textview"/>
</LinearLayout>
</ScrollView>
这是我的TabFragment3.java代码:
public class TabFragment3 extends Fragment {
TextView linkAcademy;
TextView linkRsa;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_fragment_3, container, false);
linkAcademy = (TextView) view.findViewById(R.id.linkAcademy);
linkAcademy.setMovementMethod(LinkMovementMethod.getInstance());
linkRsa = (TextView) view.findViewById(R.id.linkRSA);
linkRsa.setMovementMethod(LinkMovementMethod.getInstance());
return view;
}
我的PagerAdapter.java
public class PagerAdapter extends FragmentStatePagerAdapter {
int mNumOfTabs;
public PagerAdapter(FragmentManager fm, int numOfTabs) {
super(fm);
this.mNumOfTabs = numOfTabs;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
TabFragment1 tab1 = new TabFragment1();
return tab1;
case 1:
TabFragment2 tab2 = new TabFragment2();
return tab2;
case 2:
TabFragment3 tab3 = new TabFragment3();
return tab3;
default:
return null;
}
}
@Override
public int getCount() {
return mNumOfTabs;
}
我的 MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("XOR"));
tabLayout.addTab(tabLayout.newTab().setText("RSA"));
tabLayout.addTab(tabLayout.newTab().setText(R.string.tab_help));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
final PagerAdapter adapter = new PagerAdapter
(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, R.string.fab_info, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});