TableRowがTableLayoutをはみ出してしまいます。
具体的には、左端はTableLayoutの左端に揃っているのですが、右端が全ての行ではみ出してしまいます。
TableLayoutはwidthもheigthもmatch_parent、TableRowが5列入っています。
TableRowは全ての行にwidth="match_parent"、weight="2"、最大で7このButtonが入っています。
Buttonには、それぞれcolumnを設定しています。
なにか設定が必要なのでしょうか?
Java
1 2 3import android.os.Bundle; 4import android.support.annotation.IntegerRes; 5import android.support.v4.app.Fragment; 6import android.view.LayoutInflater; 7import android.view.View; 8import android.view.ViewGroup; 9import android.widget.Button; 10import android.widget.TableLayout; 11import android.widget.TableRow; 12import android.widget.TextView; 13 14import java.util.Calendar; 15 16 17/** 18 * A simple {@link Fragment} subclass. 19 */ 20public class FragmentChooseDay extends Fragment implements View.OnClickListener{ 21 22 private int tableRowId[] = {R.id.row0, R.id.row1, R.id.row2, R.id.row3, R.id.row4, R.id.row5}; 23 private Button button[]; 24 private TextView textView; 25 private Calendar calendar; 26 private TableRow tableRow; 27 28 public FragmentChooseDay() { 29 // Required empty public constructor 30 } 31 32 33 @Override 34 public View onCreateView(LayoutInflater inflater, ViewGroup container, 35 Bundle savedInstanceState) { 36 // Inflate the layout for this fragment 37 View view = inflater.inflate(R.layout.fragment_choose_day, container, false); 38 39 Bundle bundle = getArguments(); 40 int month = bundle.getInt("month"); 41 int year = bundle.getInt("year"); 42 textView = (TextView)view.findViewById(R.id.textView); 43 textView.setText(year + "年" + (month+1) + "月"); 44 45 calendar = Calendar.getInstance(); 46 calendar.clear(); 47 calendar.set(year, month, 1); 48 49 int num_day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); 50 51 button = new Button[num_day]; 52 53 int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); 54 int num_Row = 1; 55 int d = 1; 56 57 for(int i = 0; i < num_day; i++){ 58 button[i] = new Button(getActivity()); 59 button[i].setText(Integer.toString(d++)); 60 button[i].setOnClickListener(this); 61 tableRow = (TableRow)view.findViewById(tableRowId[num_Row]); 62 tableRow.addView(button[i],new TableRow.LayoutParams(dayOfWeek++-1)); 63 if(dayOfWeek > 7){ 64 dayOfWeek = 1; 65 num_Row++; 66 } 67 } 68 69 70 71 72 73 74 return view; 75 } 76 77 @Override 78 public void onClick(View v) { 79 80 } 81} 82
xml
1<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" 6 tools:context="×××.reminder.FragmentChooseDay"> 7 8 <!-- TODO: Update blank fragment layout --> 9 <TextView 10 android:layout_width="wrap_content" 11 android:layout_height="wrap_content" 12 android:textSize="12pt" 13 android:id="@+id/textView"/> 14 <TableLayout 15 android:layout_width="match_parent" 16 android:layout_height="match_parent"> 17 <TableRow 18 android:layout_width="match_parent" 19 android:layout_weight="1" 20 android:id="@+id/row0"></TableRow> 21 <TableRow 22 android:layout_width="match_parent" 23 android:layout_weight="2" 24 android:id="@+id/row1"></TableRow> 25 <TableRow 26 android:layout_width="match_parent" 27 android:layout_weight="2" 28 android:id="@+id/row2"></TableRow> 29 <TableRow 30 android:layout_width="match_parent" 31 android:layout_weight="2" 32 android:id="@+id/row3"></TableRow> 33 <TableRow 34 android:layout_width="match_parent" 35 android:layout_weight="2" 36 android:id="@+id/row4"></TableRow> 37 <TableRow 38 android:layout_width="match_parent" 39 android:layout_weight="2" 40 android:id="@+id/row5"></TableRow> 41 42 </TableLayout> 43 44</LinearLayout>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。