2011-07-07 8 views
1

私がしたいことは、画面の上部にグリッドビューを使用し、画面の下部にテーブルビューを使用することです。私はこれが簡単だと思ったが、明らかに私は間違っている。そしてはい、私は1時間の私の通常の検索を行い、次にstackoverflowに何かを投稿しました。Androidで2つのビューを追加する

<?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)GridLayoutとTableLayotの両方にandroid:layout_weight="0.5"を追加します。2)GridLayoutテーブルレイアウトにandroid:layout_height="fill_parent"を使用します。これは、画面内で両方のレイアウトを均等に分割します。あなたが同じように画面を分割するレイアウトをしたくない場合は残りの部分は同じまま

<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"**> 

...

あなたは0.4 & 0.6または0.8 & 0.2などのようにlayout_weightのさまざまな組み合わせを試すことができます。しかし、layout_heightをいくつかの固定ピクセルまたはディップ値に使用すると、異なるデバイス画面では異なるように見えるので、layout_weightパラメータの使用をお勧めします。

+0

これは本当にありがとうございました。私はそれが何か簡単だろうが。 – Funlamb

0

LinearLayoutのデフォルトの向きは水平です。

android:orientation="vertical"をLinearLayoutに追加します。

android:layout_height="fill_parent"をTableLayoutに設定しないと、フルスクリーンが表示されます。

+0

これは正しくありません。アンドロイドを設定すると、TableLayoutのlayout_height = "fill_parent"はフルスクリーン表示になりません。この場合、上部130pixは既にGridLayoutに割り当てられ、TableLayoutは残りの画面のみを使用します。 – Udayan

関連する問題