ScrollView无法正常工作

时间:2015-12-08 12:59:48

标签: android scrollview

enter image description here

我在以下程序中添加的滚动条无法正常工作。

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">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#D3D3D3">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:textSize="20dp"
        android:text="Over the years, Techfest's presence has been felt internationally. The technology that is being promoted has had tremendous impact on all the participants of the festival. This year Techfest provides an international platform to it's participants in some versatile competitions. Such a platform is necessary to promote exchange of ideas and exposure to participants.
Techfest welcomes you to International Challenge, where knowledge crosses borders.
"
        android:textColor="#000000"
        android:layout_marginBottom="8dp"/>
    <LinearLayout
        android:id="@+id/robowars"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:clickable="true"
        android:orientation="horizontal"
        android:layout_marginBottom="8dp"
        >

        <ImageView
            android:id="@+id/img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:src="@drawable/bullet_icon" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_margin="20dp"
            android:text="RoboWars"
            android:textSize="25dp"
            android:textColor="#000000"/>
    </LinearLayout>
    <LinearLayout
        android:id="@+id/irc"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:clickable="true"
        android:orientation="horizontal"
        >

        <ImageView
            android:id="@+id/img1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:src="@drawable/bullet_icon" />

        <TextView
            android:id="@+id/textView21"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_margin="20dp"
            android:text="International Robotics Challenge"
            android:textSize="25dp"
            android:textColor="#000000"/>
    </LinearLayout>
</LinearLayout>
</ScrollView>

JAVA文件

public class IntChal extends Fragment {
    public IntChal() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.intchal, container, false);
    }
}

对于此文件,滚动条根本不起作用,即它不会滚动。但是完全相同的逻辑似乎适用于另一个选项卡。我应该做些什么改变?提前谢谢

修改

我的错误趋势。它始终不显示文件中的最后一个按钮。希望这可以帮助。

3 个答案:

答案 0 :(得分:0)

滚动视图仅在内容超出ScreenSize时才有效。有关详细信息,请访问http://developer.android.com/reference/android/widget/ScrollView.html

答案 1 :(得分:0)

尝试将父布局添加到滚动视图,即相对布局或线性布局.i.e

例如

<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">




//here add your scrollview or other layout watever you have written  above (This is just for referance)
</RelativeLayout>

答案 2 :(得分:0)

只需将高度更改为fill_parent。

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
</ScrollView>