Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinearLayout doesn't fill tablerow even width fill_parent is called

I have a linearLayout inside a tableRow, this linearLayout contains a chart that i would like to display for my app. I read some thread saying that the child of the tableRow not need to specify its width and height, so I did it, but the chart is not displayed. If I specify the linearLayout to be width=fill_parent and height=200dp, then the linearlyLayout is only fill 1/3 of the tableRow.

<?xml version="1.0" encoding="UTF-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center_horizontal" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Record"
                android:textSize="18dp"
                android:textStyle="bold"
                android:typeface="serif" >
            </TextView>
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center_horizontal" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.3"
                android:text="Name:"
                android:textStyle="bold"
                android:typeface="serif" >
            </TextView>

            <EditText
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.7"
                android:ems="10"
                android:singleLine="true" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center_horizontal" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.3"
                android:text="Date:"
                android:textStyle="bold"
                android:typeface="serif" >
            </TextView>

            <TextView
                android:id="@+id/editRecordDate"
                android:layout_width="0dp"
                android:layout_weight="0.7"       
                android:layout_height="wrap_content" />
        </TableRow>


        <TableRow
            android:id="@+id/tableRow9"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <LinearLayout
                android:id="@+id/soundaomplitude_graphViewLinearLayout"
                android:paddingTop="4dip" >    //if I specify nothing then nothing is displayed, if I set width = fill_parent and height = 200dp, then only 1/3 of the space is occupied

            </LinearLayout>
        </TableRow>

        <TableRow
            android:id="@+id/tableRow10"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <Button
                android:id="@+id/saveEditRecord"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight=".3"
                android:text="Save" />

            <Button
                android:id="@+id/deleteEditRecord"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight=".3"
                android:text="Delete" />

            <Button
                android:id="@+id/cancelEditRecord"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_weight=".3"
                android:text="Cancel" />
        </TableRow>
    </TableLayout>

</ScrollView>
like image 778
qwr qwr Avatar asked Dec 09 '22 22:12

qwr qwr


2 Answers

I found out just set the weight = 1(or any number) for the linearLayout

<LinearLayout
                android:id="@+id/soundaomplitude_graphViewLinearLayout"
                android:layout_width="0dp"
                android:layout_height="200dp"
                android:layout_weight="1"
                android:paddingTop="4dip" />
like image 121
qwr qwr Avatar answered May 23 '23 19:05

qwr qwr


It seems that a TableRow acts as a LinearLayout, hence nesting one right inside a TableRow seems redundant. In Eclipse also, it says, that it is "useless". Therefore, you can just include your view (any view) directly inside the TableRow, instead of the LinearLayout. If it is not showing, then, there is probably some other problems.

like image 24
Nazar Merza Avatar answered May 23 '23 20:05

Nazar Merza