2014-04-09 3 views
0

두 개의 버튼 행을 포함하는 XML 파일이 있습니다. 한 행은 맨 위에 있고 다른 행은 맨 아래에 있습니다. 단추 두 줄 사이에는 뷰 클래스의 캔버스가 있습니다.앞에 버튼을 가져 오기

그러나 프로그램이 실행 중일 때는 맨 아래 줄 버튼이 나타나지 않습니다. 그것은 캔버스로 덮여있는 것 같습니다. 캔버스의 맨 아래에있는 버튼 행을 가져 오려면 어떻게해야합니까? 또는 캔버스의 높이를 어떻게 제한 할 수 있습니까?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativeLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/addbutton" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:text="Add" 
     android:textSize="9dip" /> 

    <Button 
     android:id="@+id/deletebutton" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/addbutton" 
     android:text="Delete" 
     android:textSize="9dip" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="bottom" > 

    <Button 
     android:id="@+id/nextbutton" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Next" 
     android:textSize="9dip" /> 
    <Button 
     android:id="@+id/savebutton" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Save" 
     android:textSize="9dip" /> 

    </LinearLayout> 
</RelativeLayout> 

내 MainActivity 코드 :

public class MainActivity extends Activity { 

    RelativeLayout layout; 

    static String equation, eqn; 

    public static StartDraw sd; //view class 

    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     sd = new StartDraw(this); 

     final RelativeLayout layout = (RelativeLayout) findViewById(R.id.relativeLayout); 

     final RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
       RelativeLayout.LayoutParams.MATCH_PARENT, 
       RelativeLayout.LayoutParams.MATCH_PARENT); 


     lp.addRule(RelativeLayout.BELOW, R.id.addbutton); 

     sd.setLayoutParams(lp); 

     mainLayout.addView(sd); 

     addbutton.setOnClickListener(new OnClickListener() { 
      public void onClick(View arg0) { 

      } 
     }); 
    } 

답변

0

당신이 코드에서

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

    <LinearLayout 
     android:weightSum="2" 
     android:id="@+id/topLinear" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:orientation="horizontal" > 

     <Button 
      android:layout_weight="1" 
      android:id="@+id/addbutton" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Add" 
      android:textSize="9dip" /> 

     <Button 
      android:layout_weight="1" 
      android:id="@+id/deletebutton" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="9dip" /> 
    </LinearLayout> 

    <LinearLayout 
     android:weightSum="2" 
     android:id="@+id/bottomLinear" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true" > 

     <Button 
      android:layout_weight="1" 
      android:id="@+id/nextbutton" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Next" 
      android:textSize="9dip" /> 

     <Button 
      android:layout_weight="1" 
      android:id="@+id/savebutton" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Save" 
      android:textSize="9dip" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/middleLinear" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" 
     android:layout_above="@id/bottomLinear" 
     android:layout_below="@id/topLinear"> 
    </LinearLayout> 

</RelativeLayout> 

지금이

같은 XML을 뭔가를 할에 대해 당신이 중간에 캔버스를 추가 할 수있는 방법 선형 레이아웃

0

일반적인 문제입니다. Simple 캔버스에 0.97의 가중치를 주면 버튼이 험악하게 나타납니다.

가정하자 캔버스는 다음의 LinearLayout에

<LinearLayout 
     android:id="@+id/canvas" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:weight="0.97" 
     android:orientation="vertical"> 
    </LinearLayout> 
이다 따를

당신은 너비, 높이 및 캔버스의 무게를 설정해야

관련 문제