2016-06-17 5 views
-1

アンドロイドの計算アプリを簡単に作成しようとしています。私はテーブルレイアウトを使用し、4行と4列を追加します。各列にボタンを追加します。私の問題は ここenter image description hereアンドロイドアプリの4列目を切り取ったテーブルレイアウト

は私が切り出しからそれを停止することができますどのように

<?xml version="1.0" encoding="utf-8"?> 
<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="com.tashtoons.calculator.Calculator"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentTop="true" 
     android:weightSum="1" 
     android:layout_alignParentRight="false" 
     android:layout_alignParentEnd="false"> 

     <TextView 
      android:layout_width="343dp" 
      android:layout_height="77dp" 
      android:id="@+id/answerScreen" 
      android:layout_gravity="center_horizontal" /> 

     <TableLayout 
      android:layout_width="371dp" 
      android:shrinkColumns="1" 
      android:layout_height="match_parent" 
      android:baselineAligned="true"> 


      <TableRow 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <Button 
        android:text="1" 
        android:id="@+id/button" 

        android:layout_column="0" 

        android:width="5px" /> 

       <Button 


        android:text="2" 
        android:id="@+id/button2" 
        android:layout_column="1" 
        android:width="5px" /> 

       <Button 


        android:text="3" 
        android:id="@+id/button3" 
        android:layout_column="2" 
        android:width="5px" /> 

       <Button 


        android:text="+" 
        android:id="@+id/button4" 
        android:layout_column="3" 
        android:width="5px" /> 
      </TableRow> 

      <TableRow 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <Button 

        android:text="4" 
        android:id="@+id/button5" 
        android:layout_column="0" 

        android:width="5px" /> 

       <Button 


        android:text="4" 
        android:id="@+id/button6" 
        android:layout_column="1" 
        android:width="5px" /> 

       <Button 


        android:text="5" 
        android:id="@+id/button7" 
        android:layout_column="2" 
        android:width="5px" /> 

       <Button 


        android:text="-" 
        android:id="@+id/button8" 
        android:layout_column="3" 
        android:width="5px" /> 
      </TableRow> 

      <TableRow 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <Button 

        android:text="6" 
        android:id="@+id/button9" 
        android:layout_column="0" 

        android:width="5px" /> 

       <Button 


        android:text="7" 
        android:id="@+id/button10" 
        android:layout_column="1" 
        android:width="5px" /> 

       <Button 


        android:text="8" 
        android:id="@+id/button11" 
        android:layout_column="2" 
        android:width="5px" /> 

       <Button 


        android:text="X" 
        android:id="@+id/button12" 
        android:layout_column="3" 
        android:width="5px" /> 
      </TableRow> 

      <TableRow 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <Button 

        android:text="9" 
        android:id="@+id/button13" 
        android:layout_column="0" 

        android:width="5px" /> 

       <Button 


        android:text="0" 
        android:id="@+id/button14" 
        android:layout_column="1" 
        android:width="5px" /> 

       <Button 


        android:text="%" 
        android:id="@+id/button15" 
        android:layout_column="2" 
        android:width="5px" /> 

       <Button 


        android:text="/" 
        android:id="@+id/button16" 
        android:layout_column="3" 
        android:width="5px" /> 
      </TableRow> 
     </TableLayout> 

    </LinearLayout> 
</RelativeLayout> 

以下の私のコードで、下の画像のように4列が途切れるのですか?

答えて

1

使用

android:layout_width="match_parent"

に役立つかもしれこれを試してみてくださいあなたのコードの下にコードを使用してください。あなたはすべてのButtonTextViewかなどのsame widthを与えなければならない時はいつでも

LinearLayoutのプロパティがWeightSumです。これは部分を分割して等しいことができます。

あなたのXMLコードを以下の形式に変更してください。

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="com.example.softeng.xxy.ThirdActivity"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="50dp" 
     android:id="@+id/firstRow"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="4"> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="1" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="2" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="3" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="+" /> 

     </LinearLayout> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/secondRow" 
     android:layout_below="@+id/firstRow"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="4"> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="4" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="4" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="5" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="-" /> 

     </LinearLayout> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/thirdRow" 
     android:layout_below="@+id/secondRow"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="4"> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="6" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="7" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="8" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="X" /> 

     </LinearLayout> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/forthRow" 
     android:layout_below="@+id/thirdRow"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="4"> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="9" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="0" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="%" /> 

      <Button 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="/" /> 

     </LinearLayout> 
    </RelativeLayout> 

</RelativeLayout> 

出力:

enter image description here

0

それはあなた、あなたのTableLayout

代わりの

android:layout_width="371dp"代わり

0

ビューは重量= 1を有する場合、あなたは彼らがさえ持たせる0dpするlayout_widthを設定する必要があります画面上の量またはスペース

関連する問題