是否可以在不导入Android ScrollView类的情况下创建scrollview对象?

时间:2017-03-05 05:19:49

标签: java android scrollview

我正在尝试解释Java代码,但我没有看到如何在不导入ScrollView类的情况下创建ScrollView对象。谁能解释为什么这是可能的?我也没有在XML文件中看到任何ScrollView标签。这是以下代码:

MainActivity.Java

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.*;

public class Form extends Activity {

    ScrollView sv;
    TableLayout myLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sv = new ScrollView(this);
        myLayout = new TableLayout (this);
        drawScreen();
    }
    //more code...
    ///....

activity_main.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: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=".MainActivity" >

    <TextView
      android:id="@+id/text1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/textView"
    />

</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

Option Explicit

Sub Pivot()

Dim PSheet          As Worksheet
Dim DSheet          As Worksheet
Dim PTable          As PivotTable
Dim PCache          As PivotCache
Dim PRange          As Range
Dim LastRow         As Long
Dim LastCol         As Long

Set PSheet = Worksheets("Summary")
Set DSheet = Worksheets("Content")

With DSheet
    LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column

    Set PRange = .Range("A1").Resize(LastRow, LastCol) ' set data range for Pivot Table
End With

' Set the Pivot Cache
Set PCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=PRange, Version:=xlPivotTableVersion14)

' add this line in case the Pivot table doesn't exit >> first time running this Macro
On Error Resume Next
Set PTable = PSheet.PivotTables("ERA_Dashboard") ' check if "ERA_Dashboard" Pivot Table already created (in past runs of this Macro)

On Error GoTo 0
If PTable Is Nothing Then

    ' create a new Pivot Table in "Summary" sheet
    Set PTable = PSheet.PivotTables.Add(PivotCache:=PCache, TableDestination:=PSheet.Range("A1"), TableName:="ERA_Dashboard")

Else
    ' just refresh the Pivot cache with the updated Range
    PTable.ChangePivotCache PCache
    PTable.RefreshTable
End If

End Sub

导入android.widget下的所有内容,包括ScrollView。