有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java My ScrollView不会滚动

我使用GraphViewAPI制作了两个图,并将它们分别放在两个LinearLayout中。这两种布局都位于ScrollView内,而Relativelayout内的ScrollView内。出于某种原因,ScrollView不会滚动:

XML:

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:tools="http://schemas.安卓.com/tools"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    安卓:paddingLeft="@dimen/activity_horizontal_margin"
    安卓:paddingRight="@dimen/activity_horizontal_margin"
    安卓:paddingTop="@dimen/activity_vertical_margin"
    安卓:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.adrian.desktop.ViewProgress$PlaceholderFragment">
    <ScrollView
        安卓:layout_width="fill_parent"
        安卓:layout_height="fill_parent"
        安卓:id="@+id/scrollView"
        安卓:fillViewport="true">
        <LinearLayout
            安卓:layout_width="match_parent"
            安卓:layout_height="match_parent"
            安卓:layout_marginTop="280dp"
            安卓:orientation="vertical">
        <LinearLayout
            安卓:id="@+id/Graph"
            安卓:orientation="vertical"
            安卓:layout_width="match_parent"
            安卓:layout_height="0dp"
            安卓:layout_weight="1">
        </LinearLayout>
            <LinearLayout
                安卓:id="@+id/Graph2"
                安卓:layout_below="@+id/Graph"
                安卓:orientation="vertical"
                安卓:layout_width="match_parent"
                安卓:layout_height="0dp"
                安卓:layout_weight="1">
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

爪哇:

package com.example.adrian.desktop;

import 安卓.graphics.Color;
import 安卓.os.Bundle;
import 安卓.support.v4.app.Fragment;
import 安卓.support.v4.app.FragmentActivity;
import 安卓.view.LayoutInflater;
import 安卓.view.Menu;
import 安卓.view.MenuItem;
import 安卓.view.View;
import 安卓.view.ViewGroup;
import 安卓.widget.LinearLayout;    
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphView.GraphViewData;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.LineGraphView;

public class ViewProgress extends FragmentActivity {    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_progress);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment())
                .commit();
        }
        GraphView graphView = new LineGraphView(this, "example");
        // first init data
        // sin curve
        int num = 150;
        GraphViewData[] data = new GraphViewData[num];
        double v=0;
        for (int i=0; i<num; i++) {
            v += 0.2;
            data[i] = new GraphViewData(i, Math.sin(v));
        }
        GraphViewSeries seriesSin = new GraphViewSeries("This Year", new GraphViewSeries.GraphViewSeriesStyle(Color.rgb(200, 50, 00), 3), data);
         // cos curve
        data = new GraphViewData[num];
        v = 0;
        for (int i=0; i<num; i++) {
            v += 0.2;
            data[i] = new GraphViewData(i, Math.cos(v));
        }
        GraphViewSeries seriesCos = new GraphViewSeries("Last Year", new GraphViewSeries.GraphViewSeriesStyle(Color.rgb(90, 250, 00), 3), data);
        /*
        * create graph
        */
        graphView = new LineGraphView(this, "Grades");
        // add data
        graphView.addSeries(seriesCos);
        graphView.addSeries(seriesSin);
        // optional - set view port, start=2, size=10
        graphView.setViewPort(2, 10);
        graphView.setScalable(true);
        // optional - legend
        graphView.setShowLegend(true);
        graphView.setLegendAlign(GraphView.LegendAlign.BOTTOM);
        graphView.setHorizontalLabels(new String[] {"Last Year", "First Term", "Second Term", "Third Term"});
        graphView.setVerticalLabels(new String[] {"A*", "A", "B","C","D","E","F"});
        LinearLayout layout = (LinearLayout) findViewById(R.id.Graph);
        LinearLayout layout2 = (LinearLayout)findViewById(R.id.Graph2);
        layout.addView(graphView);
        // init example series data
        GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
            new GraphViewData(1, 2.0d)
                , new GraphViewData(2, 1.5d)
                , new GraphViewData(3, 2.5d)
                , new GraphViewData(4, 1.0d)
        });
        GraphView graphView2 = new LineGraphView(
           this // context
           , "Performance" // heading
        );
        graphView2.addSeries(exampleSeries); // data    
        layout2.addView(graphView2);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.view_progress, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {    
        public PlaceholderFragment() {
        }    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_view_progress, container, false);
            return rootView;
        }
    }
}

共 (0) 个答案