2011-10-05 3 views
0

다음 문제에 대한 답을 찾기 위해 net을 검색했습니다. 그러나 아무 대답도 찾아 내지 않았다. 나는 여러 가지 방법을 시도했지만 안드로이드에서는 아직 초보자입니다. 내가 스크롤에 관한 그물에 발견하는 공식 문서와 http://developer.android.com에 스크롤의 예입니다 씨 Senthilkumar의 How to scroll the screen, Kakka47의 ScrollView only part of the screen는 제목 위에서 알 수있는 바와 같이 이것은 매우 일반적인 요구 사항 인 등Android 보이는 화면의 일부를 스크롤 가능하게 만들려면

, A scroll view with only part of the screen scrolling darrinps. 그림과 같이 다음과 같은 화면 레이아웃이 있습니다.

화면 제목이 안정되어 있습니다. 테이블 레코드는 열 제목 아래로 스크롤해야합니다. 나는 AbsoluteLayout을 가지고있다. (필자는 그것이 더 이상 사용되지 않지만 특정 필요에 의해서만 사용할 수있다.) 내부에는 scrollview가 있고 scrollview에는 TableLayout이있다.

사용자는 "추가"버튼을 클릭하여받은 주문을 추가합니다. 한 행에 한 명령. 행이 증가하면 보이는 영역을 벗어납니다. 따라서 스크롤하여 사용자가 액세스 할 수있게하고 싶습니다. 그러나이 부분은 스크롤되지 않습니다. 나는 나의 코드 목록을 주었다. 어떻게해야할지 말해줘.

코드 :

package com.BookOrders; 

    import java.util.Calendar; 

    import android.app.Activity; 
    import android.app.DatePickerDialog; 
    import android.app.Dialog; 
    import android.content.Context; 
    import android.os.Bundle; 
    import android.view.View; 
    import android.widget.AbsoluteLayout; 
    import android.widget.Button; 
    import android.widget.CheckBox; 
    import android.widget.DatePicker; 
    import android.widget.EditText; 
    import android.widget.ScrollView; 
    import android.widget.Spinner; 
    import android.widget.TableLayout; 
    import android.widget.TableRow; 
    import android.widget.TextView; 

    //import android.widget.TableRow.LayoutParams; 

    @SuppressWarnings("deprecation") 
    public class BookOrders extends Activity implements ScrollViewListener{ 
    /** Called when the activity is first created. */ 
private TextView BookingDateDisplay;  
private Button ChangeDate, AddRec, DeleteRec, SaveAll; 
private CheckBox SelectedAll, SelectedRec; 
private ObservableScrollView CustomScroller = null; 
private ObservableScrollView CustomScrolled = null; 
private int ChangedYear;  
private int ChangedMonth;  
private int ChangedDay; 
public Context CurrentContext, UsedContext; 
static final int DATE_DIALOG_ID = 0; 
int IdGenerator = 100000; 
int Number_of_Records = 0; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.main); 
    @SuppressWarnings("deprecation") 
    final AbsoluteLayout main = (AbsoluteLayout)findViewById(R.id.widget0); 
    CurrentContext = main.getContext(); 
    //final ScrollView ScrollControl = (ScrollView)findViewById(R.id.scroller); 
    //final AbsoluteLayout LayerControl = (AbsoluteLayout)findViewById(R.id.FinalLayer); 
    // UsedContext = LayerControl.getContext(); 
// capture our View elements 
    CustomScroller = (ObservableScrollView) findViewById(R.id.scrollContainer); 

    BookingDateDisplay = (TextView) findViewById(R.id.BookedDate);   
    ChangeDate = (Button) findViewById(R.id.pickDate);   
    AddRec = (Button) findViewById(R.id.AddRecord); 
    DeleteRec = (Button) findViewById(R.id.DeleteRecord); 
    SaveAll = (Button) findViewById(R.id.SaveRecord); 
    SelectedAll = (CheckBox) findViewById(R.id.SelectAll); 

    // add a click listener to the button   
    ChangeDate.setOnClickListener(new View.OnClickListener() {    
     public void onClick(View v) {     
      showDialog(DATE_DIALOG_ID);    
     } 
    }); 
    AddRec.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View AddRecView) { 
      IdGenerator = IdGenerator+10; 
      UsedContext = AddRecView.getContext(); 
      TableRow Tr = new TableRow(UsedContext); 
      for (int controls=0; controls<6; controls++) { 

       if (controls==0){ 
        CheckBox RecordCheck = new CheckBox(UsedContext); 
        RecordCheck.setId(IdGenerator+controls); 
        RecordCheck.setTag("CheckBoxTag"); 
        RecordCheck.setHeight(20); 
        RecordCheck.setWidth(25); 
        Tr.addView(RecordCheck); 
       } 
       if ((0 < controls) && (controls<5)){ 
        Spinner Record = new Spinner(UsedContext); 
        Record.setId(IdGenerator+controls); 
        //Record.setMinimumHeight(20); 
        //Record.setMinimumWidth(90); 
        Tr.addView(Record); 
       } 
       if (controls==5){ 
        EditText OrderQuantity = new EditText(UsedContext); 
        OrderQuantity.setId(IdGenerator+controls); 
        //OrderQuantity.setHeight(20); 
        //OrderQuantity.setWidth(90); 
        Tr.addView(OrderQuantity); 
       } 

      } 
      TableLayout Orders = (TableLayout)findViewById(R.id.OrderData); 
      Orders.addView(Tr); 
      // Scrolls to line before last - why? 
      final ScrollView ScrollAttempt = (ScrollView) findViewById(R.id.scrollContainer); 
      ScrollAttempt.post(new Runnable() { 
       public void run() { 
        ScrollAttempt.fullScroll(View.FOCUS_DOWN); 
       } 

      }); 
      Number_of_Records = Number_of_Records + 1; 
      } 

    }); 
    // updates the date in the TextView  
    private void updateDisplay() {   
    BookingDateDisplay.setText(   
      new StringBuilder()      
      .append(ChangedDay).append("-") 
      .append(ChangedMonth + 1).append("-")  // Month is 0 based so add 1 
      .append(ChangedYear).append(" "));  

} 
// the call back received when the user "sets" the date in the dialog  

    private DatePickerDialog.OnDateSetListener DateSetListener =    
     new DatePickerDialog.OnDateSetListener(){ 
      public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {      
      ChangedYear = year;      
      ChangedMonth = monthOfYear;      
      ChangedDay = dayOfMonth;      
      updateDisplay();     
      }    
     }; 
     @Override 
     protected Dialog onCreateDialog(int id) {  
      switch (id) {  
       case DATE_DIALOG_ID:   
        return new DatePickerDialog(this, DateSetListener, ChangedYear, ChangedMonth, ChangedDay);  
        }  
      return null; 
      } 
     public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) { 
      if(scrollView == CustomScroller) { 
       CustomScrolled.scrollTo(x, y); 
      } else if(scrollView == CustomScrolled) { 
       CustomScroller.scrollTo(x, y); 
      } 
     } 

} 

main.xml :

<?xml version="1.0" encoding="utf-8"?> 
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/widget0" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <!-- <ImageButton android:text="Date" android:layout_height="20px" android:layout_width="32px" android:id="@+id/BDate" android:layout_x="274dip" android:layout_y="51dip"></ImageButton> --> 

    <TextView 
     android:id="@+id/Title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_x="81dip" 
     android:layout_y="10dip" 
     android:background="#0ff0ff" 
     android:gravity="center" 
     android:text="Order Booking" 
     android:textColor="#330000" 
     android:textSize="20sp" 
     android:textStyle="bold" 
     android:typeface="serif" > 
    </TextView> 

    <TextView 
     android:id="@+id/BDate_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_x="277dip" 
     android:layout_y="52dip" 
     android:gravity="right" 
     android:text="Booked on:" 
     android:textSize="12sp" > 
    </TextView> 

    <TextView 
     android:id="@+id/BookedDate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_x="350dip" 
     android:layout_y="52dip" 
     android:text="" 
     android:textSize="12sp" > 
    </TextView> 

    <Button 
     android:id="@+id/pickDate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_x="400dip" 
     android:layout_y="15dip" 
     android:text="Change Date" 
     android:textSize="10sp" > 
    </Button> 

    <View 
     android:layout_width="wrap_content" 
     android:layout_height="36dp" 
     android:layout_y="68dp" 
     android:background="@drawable/gradient" > 
    </View> 

    <Button 
     android:id="@+id/AddRecord" 
     android:layout_width="120dp" 
     android:layout_height="34dp" 
     android:layout_x="10dip" 
     android:layout_y="71dip" 
     android:text="Add" 
     android:textSize="10sp" > 
    </Button> 

    <Button 
     android:id="@+id/DeleteRecord" 
     android:layout_width="120dp" 
     android:layout_height="34dp" 
     android:layout_x="140dp" 
     android:layout_y="71dp" 
     android:text="Delete" 
     android:textSize="10sp" > 
    </Button> 

    <Button 
     android:id="@+id/ClearRecord" 
     android:layout_width="120dp" 
     android:layout_height="34dp" 
     android:layout_x="270dp" 
     android:layout_y="71dp" 
     android:text="Clear" 
     android:textSize="10sp" > 
    </Button> 

    <Button 
     android:id="@+id/SaveRecord" 
     android:layout_width="120dp" 
     android:layout_height="34dp" 
     android:layout_x="400dp" 
     android:layout_y="71dp" 
     android:text="Save" 
     android:textSize="10sp" > 
    </Button> 

    <View 
     android:layout_width="wrap_content" 
     android:layout_height="1dp" 
     android:layout_y="110dp" 
     android:background="@drawable/gradient" > 
    </View> 

    <CheckBox 
     android:id="@+id/SelectAll" 
     android:layout_width="wrap_content" 
     android:layout_height="20dp" 
     android:layout_x="10dip" 
     android:layout_y="115dip" 
     android:text="Select All" 
     android:textSize="10sp" > 
    </CheckBox> 

    <TextView 
     android:id="@+id/Company" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_x="95dip" 
     android:layout_y="115dip" 
     android:background="#666666" 
     android:text="Company" 
     android:textColor="#000000" 
     android:textSize="12sp" > 
    </TextView> 

    <TextView 
     android:id="@+id/Product" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_x="200dip" 
     android:layout_y="115dip" 
     android:background="#666666" 
     android:text="Product" 
     android:textColor="#000000" 
     android:textSize="12sp" > 
    </TextView> 

    <TextView 
     android:id="@+id/Code" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_x="300dip" 
     android:layout_y="115dip" 
     android:background="#666666" 
     android:text="Code" 
     android:textColor="#000000" 
     android:textSize="12sp" > 
    </TextView> 

    <TextView 
     android:id="@+id/Model" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_x="380dp" 
     android:layout_y="115dp" 
     android:background="#666666" 
     android:text="Model" 
     android:textColor="#000000" 
     android:textSize="12sp" > 
    </TextView> 

    <TextView 
     android:id="@+id/Quantity" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_x="470dp" 
     android:layout_y="115dp" 
     android:background="#666666" 
     android:text="Quantity" 
     android:textColor="#000000" 
     android:textSize="12sp" > 
    </TextView> 

    <View 
     android:id="@+id/view1" 
     android:layout_width="wrap_content" 
     android:layout_height="1dp" 
     android:layout_x="0dip" 
     android:layout_y="134dip" 
     android:background="@drawable/gradient" > 
    </View> 

    <com.BookOrders.ObservableScrollView 
     android:id="@+id/scrollContainer" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_x="1dp" 
     android:layout_y="140dp" 
     android:clickable="true" 
     android:fadeScrollbars="false" 
     android:fillViewport="true" > 

     <TableLayout 
      android:id="@+id/OrderData" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:stretchColumns="0,1,2,3,4" /> 
    </com.BookOrders.ObservableScrollView> 

</AbsoluteLayout> 

답변

1

당신이 ScrollView을 시도 했습니까? 그것으로

<ScrollView 
     android:id="@+id/coupons_details_scroll_view" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 
<!--You can nest any other views here, and they will be scrollable, but take care of views that have their own scrolling capabilities like ListView --> 
</ScrollView> 

행운을 빕니다 :)

+0

나는 먼저 을 시도했다. 작동하지 않으면 ObservableScrollView 클래스를 http://code.google.com/p/iosched/source/browse/android/src/com/google/android/apps/iosched/ui/widget/ObservableScrollView에서 가져 왔습니다. .java –

1

나는 이것에 대한 해결책을했다 : 여기 ScrollView을 사용하는 방법의 예는 더 ScrollViewhere

에 대해 당신은 찾을 수 있습니다. 알고 싶은 사람은 먼저 다음 링크를 클릭하십시오. http://blog.stylingandroid.com/archives/447

이 논리를 사용했습니다. 그러나 사용자가 "추가"버튼을 클릭하면 동적으로 행이 생성됩니다. 유일한 문제는 회 전자를 사용하면 높이를 0으로 설정할 수 없다는 것입니다.

니틴

+0

언급 된 URL이 변경된 것 같습니다. Mark Allison https://blog.stylingandroid.com/scrolling-table-part-2/ – SoloPilot

관련 문제