2012-07-07 2 views
-1

다음은 2 프레임 레이아웃 내에 2 개의 테이블 레이아웃이있는 xml 파일과 함께 내 코드입니다. 첫 번째 테이블 레이아웃은 테이블의 제목을 설정하는 데 사용되는 반면 두 번째 테이블은 두 번째 테이블 레이아웃에서 행을 동적으로 설정하는 데 사용되지만 제목이 완벽하게 맞는 것처럼 보이지만 제목 아래에서 올바르게 정렬되지 않습니다. 테이블 레이아웃에 대한 매개 변수 설정 중 실수. 나는 고쳐지고있다. 어떤 도움을 주시면 감사하겠습니다. 고맙습니다.올바르게 안드로이드에서 테이블 레이아웃의 방향을 설정하는 방법

package com.table; 

import android.app.Activity; 
import android.graphics.Bitmap; 
import android.graphics.Color; 
import android.graphics.YuvImage; 
import android.os.Bundle; 
import android.text.Editable; 
import android.text.InputType; 
import android.text.TextWatcher; 
import android.util.Log; 
import android.view.Gravity; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.RelativeLayout.LayoutParams; 
import android.widget.ImageView; 
import android.widget.LinearLayout; 
import android.widget.TableLayout; 
import android.widget.TableRow; 
import android.widget.TextView; 
import java.util.List; 





public class TableActivity extends Activity 
{ 
    TableLayout table,table_values; 
    Button scan,add; 
    String value; 



    EditText ed1; 


    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     createTableLayout(); 
     addrows(); 


     scan = (Button)findViewById(R.id.read); 
     if(scan != null) 
     { 
      scan.setOnClickListener(new OnClickListener() { 

       public void onClick(View v) 
       { 

       } 
      }); 
     } 








     try 
     { 
      scan.setOnClickListener(new View.OnClickListener() 
      { 

       @Override 
       public void onClick(View v) 
       { 
        setContentView(R.layout.code); 
        add=(Button)findViewById(R.id.button2); 

       } 
      }); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 


     try { 
      add.setOnClickListener(new View.OnClickListener() 
      { 

       @Override 
       public void onClick(View v) 
       { 


       } 
      }); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 








    } 




    public void createTableLayout() 
    { 
      table = (TableLayout) findViewById(R.id.tableLayout1); 
      // table.setBackgroundResource(R.drawable.sky); 
      //TableRow tr_heading = new TableRow(this); 
      table_values = (TableLayout) findViewById(R.id.tableLayout2); 
      TableRow tr_heading = new TableRow(this); 
      tr_heading.setId(10); 
      tr_heading.setBackgroundColor(Color.GRAY); 
      tr_heading.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.FILL_PARENT)); 



      TextView Serial = new TextView(this); 
      Serial.setId(20); 
      Serial.setText("Sr No. "); 
      Serial.setTextColor(Color.BLACK); 
      tr_heading.addView(Serial); // add the column to the table row 








      //TextView label_question = new TextView(this); 
      TextView Name = new TextView(this); 
      Name.setId(20); 
      Name.setText("ID  "); 
      Name.setWidth(40); 
      Name.setTextColor(Color.BLACK); 
      tr_heading.addView(Name); // add the column to the table row 

      //TextView label_question = new TextView(this); 
      TextView Quantity = new TextView(this); 
      Quantity.setId(20); 
      Quantity.setText("        Quantity"); 
      Quantity.setTextColor(Color.BLACK); 
      tr_heading.addView(Quantity); // add the column to the table row 


      TextView amt = new TextView(this); 
      amt.setId(20); 
      amt.setText("   Amt"); 
      amt.setTextColor(Color.BLACK); 
      tr_heading.addView(amt); 


      table.addView(tr_heading, new TableLayout.LayoutParams(
        LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT)); 

    } 


      //--------------------------Adding Rows to your Table -------------------------------------- 

     public void addrows() 
      { 

          Integer count = 0; 
          for (int count1 = 0; count1<3; count1++) 
          { 


           TableRow tr = new TableRow(this); 
           if (count % 2 != 0) 
           tr.setId(100 + count); 
           tr.setClickable(true); 

           tr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 


           TextView sr = new TextView(this); 
           sr.setText("1"); 
           //sr.setGravity(Gravity.CENTER); 
           sr.setPadding(2, 0, 5, 0); 
           sr.setTextColor(Color.WHITE); 
           sr.setClickable(true); 
           tr.addView(sr); 








           TextView idval = new TextView(this); 

           idval.setText(value); 
           idval.setGravity(Gravity.CENTER); 
           idval.setText("    fdfj"); 
           idval.setPadding(2, 0, 5, 0); 

           idval.setTextColor(Color.WHITE); 
           idval.setClickable(true); 
           tr.addView(idval); 


           EditText quantity = new EditText(this); 
           //quantity.setId(200 + count); 
           quantity.setGravity(Gravity.CENTER); 
           quantity.setTextColor(Color.BLACK); 
         //  quantity.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
         //  quantity.setWidth(1); 
           quantity.setText("1"); 
           quantity.setInputType(InputType.TYPE_CLASS_NUMBER); 
           int val=Integer.parseInt((quantity.getText().toString())); 
         //  quantity.setHeight(2); 
           quantity.setEnabled(true); 
           quantity.setPadding(2,0,5,0); 
           tr.addView(quantity); 


           TextView amount=new TextView(this); 
           amount.setGravity(Gravity.CENTER); 
           amount.setTextColor(Color.WHITE); 
           amount.setClickable(true); 
           //amount.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
           amount.setEnabled(true); 
           //amount.setText("    1000"); 
           amount.setText(String.valueOf(( val*10))); 
         //  amount.setWidth(1); 
         //  amount.setHeight(2); 
           tr.addView(amount); 


           // finally add this to the table row 
           table_values.addView(tr, new TableLayout.LayoutParams(
             LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
           count++; 



          } 
      } 




} 



    **Xml file is below: 
    <?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <FrameLayout 
     android:id="@+id/frameLayout1" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent"> 
    <FrameLayout 
     android:id="@+id/frameLayout2" 
     android:layout_height="match_parent" 
     android:layout_marginTop="40dp" 
     android:layout_marginBottom="70dp" 
     android:layout_width="match_parent"> 
      <TableLayout 
       android:layout_height="wrap_content" 
       android:id="@+id/tableLayout1" 
       android:layout_width="match_parent"> 
      </TableLayout> 
    <FrameLayout 
       android:id="@+id/frameLayout4" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
     <TableLayout 
     android:layout_height="wrap_content" android:id="@+id/tableLayout2" android:layout_width="match_parent"> 
    </TableLayout> 

     </FrameLayout> 

    </FrameLayout> 
    <FrameLayout android:id="@+id/frameLayout3" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_gravity="bottom"> 

     <Button 
      android:text="Scan" 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:layout_marginLeft="10dp"> 
     </Button> 
     <Button 
      android:id="@+id/button2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button" android:layout_gravity="center_horizontal"> 
     </Button> 

    </FrameLayout> 
    </FrameLayout> 

</LinearLayout> 


screen shot: http://i.stack.imgur.com/0nqsR.png 


![This is ther screen image[1] 


    [1]: http://i.stack.imgur.com/0nqsR.png 
+1

예상되는 결과는 무엇인가 :

여기 TableLayout을의 예? 당신이하고 싶은 것을 스케치 해 주시겠습니까? 당신이 쓴 것에 의해 당신이하고 싶은 것을 상상하기는 어렵습니다. –

답변

1

당신은 프레임 율이 2이므로 2 개의 프레임이 서로 겹치므로 서로 겹치는 부분이 없으므로 서로 겹치지 않습니다.

어쨌든 단일 tableLayout 또는 listView 또는 gridLayout을 사용하는 것이 좋습니다.

http://wowjava.wordpress.com/2011/04/01/dynamic-tablelayout-in-android/

+0

머리글의 수량 필드 아래에 편집 텍스트 필드를 배치하고 싶습니다.이 필드는 vakue 10과 함께 id에 가깝게 배치되어 있습니다. 값 10은 금액 필드 아래에 있어야합니다. – Sumit

관련 문제