2011-07-07 43 views
1

所以我想要做的是在屏幕頂部使用gridview,在屏幕下半部使用table view。我認爲這很容易,但顯然我錯了。是的,我做了我平時搜索1小時,然後張貼在stackoverflow上的東西。在Android中添加兩個視圖

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


<GridView 
android:id="@+id/gridview" 
android:layout_width="fill_parent" 
android:numColumns="4" 
android:verticalSpacing="10dp" 
android:horizontalSpacing="10dp" 
android:stretchMode="columnWidth" 
android:gravity="center" 
android:layout_height="130dp"/> 

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

<TableRow> 
    <TextView 
    android:text="Name:" 
    android:id="@+id/TextView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 


    <EditText 
    android:hint="Name" 
    android:id="@+id/projectName" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/> 
</TableRow> 

<TableRow> 
    <TextView 
    android:text="Start" 
    android:id="@+id/startText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 


    <Button 
    android:text="Push" 
    android:id="@+id/startdate" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:onClick="startDate"/> 

</TableRow> 

<TableRow> 
    <TextView 
    android:text="Finish" 
    android:id="@+id/finishText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 


    <Button 
    android:id="@+id/finishdate" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:onClick="finishDate"/> 
</TableRow> 
</TableLayout> 

</LinearLayout> 

也許這很容易。也許我應該在早上上牀睡覺。 感謝您的幫助。

+0

它現在的樣子。你有什麼問題? – Rasel

回答

1

1)將android:orientation="vertical"添加到LinearLayout。

2)將android:layout_height="fill_parent"用於BOTH Grid n表格佈局,並且還在GridLayout和TableLayot中添加android:layout_weight="0.5"。這將同時在屏幕上劃分兩個佈局。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:stretchColumns="1" android:orientation="vertical"> 


    <GridView android:id="@+id/gridview" android:layout_width="fill_parent" 
     android:numColumns="4" android:verticalSpacing="10dp" 
     android:horizontalSpacing="10dp" android:stretchMode="columnWidth" 
     android:gravity="center" **android:layout_height="fill_parent"** 
     **android:layout_weight="0.5"** /> 

    <TableLayout android:layout_width="fill_parent" 
     **android:layout_height="fill_parent"** android:stretchColumns="1" 
     **android:layout_weight="0.5"**> 

其餘部分保持一樣的...

你可以嘗試layout_weight的不同組合,像0.4 & 0.6或0.8 & 0.2等,如果你不想要的佈局均分屏幕。但是,如果您使用layout_height來設置某個固定像素或傾角值,則它會在不同的設備屏幕上顯示不同......所以我建議使用layout_weight參數。

+0

這是非常感謝你。我雖然會很容易。 – Funlamb

0

LinearLayout的默認方向是水平的。

android:orientation="vertical"添加到您的LinearLayout。

並且不要將android:layout_height="fill_parent"設置爲您的TableLayout,否則會佔用全屏。

+0

這是不正確的,將android:layout_height =「fill_parent」設置爲TableLayout將不會全屏顯示。因爲在這種情況下頂部130pix已經分配給GridLayout,並且TableLayout將只使用可用的屏幕剩餘部分。 – Udayan

相關問題