I'm am completely new to programming android apps in eclipse.
With that said, I based myself off code on the internet and and came up with this xml file for my layout. I can not get the four buttons to have the same size, and when I play around with the other parts, the progress bar and texts under it, they go bananas, displaying it off screen.
Could someone review the code and tell me what is gong on? I simply don't understand. Here is a picture.
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="10dp" >
<TextView
android:id="@+id/txt_currentDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="6"
android:gravity="center"
android:text="Current Date"
android:textSize="18dp"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/progressBarRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp" >
<ProgressBar
android:id="@+id/DailyCalorieProgress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="3"
android:progress="80" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp" >
<TextView
android:id="@+id/textView1"
android:gravity="center"
android:text="Calorie Limit : "
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView2"
android:gravity="center"
android:text="2000 " >
</TextView>
<TextView
android:id="@+id/textView3"
android:gravity="center"
android:text="Calories Left : "
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView4"
android:gravity="center"
android:text="552" >
</TextView>
</TableRow>
<TextView
android:id="@+id/textView5"
android:gravity="center_horizontal"
android:text="____________________" >
</TextView>
<TableLayout
android:id="@+id/ButtonLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:stretchColumns="0,1" >
<TableRow
android:id="@+id/buttonRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:paddingTop="10dp" >
<Button
android:id="@+id/btn_addFood"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp"
android:text="Add Food"/>
<Button
android:id="@+id/btn_addExercise"
android:layout_width="130dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp"
android:text="Add Exercise"/>
</TableRow>
<TableRow
android:id="@+id/buttonRow2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_recWeight"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:text="Record Weight" />
<Button
android:id="@+id/btn_sgstMeal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:text="Suggest Meal/Exercise" />
</TableRow>
</TableLayout>
</TableLayout>
Edits:
It now almost works.
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="10dp" >
<TextView
android:id="@+id/txt_currentDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="6"
android:gravity="center"
android:text="@string/CurrentDate"
android:textSize="18dp"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/progressBarRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp" >
<ProgressBar
android:id="@+id/DailyCalorieProgress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="3"
android:progress="80" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp" >
<TextView
android:id="@+id/textView1"
android:gravity="center"
android:text="@string/CalorieLimit"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView2"
android:gravity="center"
android:text="@string/CalorieLimitData" >
</TextView>
<TextView
android:id="@+id/textView3"
android:gravity="center"
android:text="@string/CaloriesLeft"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView4"
android:gravity="center"
android:text="@string/CaloriesLeftData" >
</TextView>
</TableRow>
<TextView
android:id="@+id/textView5"
android:gravity="center_horizontal"
android:text="@string/Line" >
</TextView>
<TableRow
android:id="@+id/buttonRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
android:paddingTop="10dp" >
<Button
android:id="@+id/btn_addFood"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="@string/AddFood"/>
<Button
android:id="@+id/btn_addExercise"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="@string/AddExercise"/>
</TableRow>
<TableRow
android:id="@+id/buttonRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
android:paddingTop="10dp" >
<Button
android:id="@+id/btn_recWeight"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="@string/RecordWeight" />
<Button
android:id="@+id/btn_sgstMeal"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="@string/SuggestedMeal_Exercise" />
</TableRow>
</TableLayout>
Your layout isn't really "efficient". But anyway..to solve your problem you have to set your TableRow (the ones that contain your buttons) to
android:layout_width="fill_parent"
android:layout_height="wrap_content"
and all of your buttons to
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
0dip does not make anything. But because of the weight param android does the work for measuring the actual size anyway so you do not need to provide a "relevant" value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With