2017-02-20 14 views
0

私は、画面の下部にシンプルな単一のグリッドを配置したいと思います。ここでは、望ましい結果のスクリーンショットがあるandroid table layout - simple exmple

simple grid I am looking for

simple grid I am looking

私はたった3行の高マトリックスを示し、「ウィンドウ」を作成し、ユーザーがスクロールできるようにすることができれば、それはクールになります/それを介して飛んでくる。これにより、画面が回転すると、リスト/マトリックスは水平モードで画面全体を消費しません。

私はテーブルレイアウトを使用する必要がありますか?以下は私のactivity_main.xmlです。私は、最下位/ 3番目のtextviewを、複数の行を持つ3列のテキストを含むテーブルレイアウトに置き換えたいと思います。

もちろん、ウィジェットをドラッグ&ドロップすることはできますが、行と列をどのように埋め込むことができますか?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    tools:context="com.example.ftonyan.gps7.MainActivity"> 

    <TextView 
     android:text="abc" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/textView2" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:textAlignment="center" /> 

    <Chronometer 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/def" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="vertical" 
     android:gravity="bottom" 
     android:text="Log:" 
     android:maxLines="8" 
     android:layout_marginTop="31dp" 
     android:layout_below="@+id/textView2" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <TextView 
     android:text="ghi" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="19dp" 
     android:id="@+id/textView3" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" /> 

</RelativeLayout> 

答えて

1

thisをご覧ください。だからあなたの場合には、あなたが最後に以下を追加することができます:あなたのコードで

<TableLayout 
    android:id="table" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:stretchColumns="1"/> 

をTableLayoutの参照を取得、あなたがして、その後、3つの列と行を膨らませることができ、あなたのTableLayoutに行を追加します。

​​

等...

あなた膨張した行のレイアウトは、次のようになります:

<TableRow> 
     <TextView 
      android:id="@+id/first" 
      android:text="first" 
      android:padding="3dip" /> 
     <TextView 
      android:id="@+id/second" 
      android:text="second" 
      android:gravity="center" 
      android:padding="3dip" /> 
     <TextView 
      android:id="@+id/third" 
      android:text="third" 
      android:gravity="right" 
      android:padding="3dip" /> 
</TableRow> 

各テキストビューにIDを付けることができます。これにより、各行を拡張するときにテキストビューを参照してデータを設定できます。

データやデータのサイズによっては、RecyclerViewでGridLayoutManagerを使用して、何をしようとしているのかをより効率的に行うことができます。

+0

ありがとうございます。私のデータは、深さ20行、幅4列までです。それは巨大ではありませんが、行のあるグリッドは読みやすくします。私はそれが私のアプリに既にtextviewsを保持しながら私の画面の下部に収まるようにしたい...上部に。 tableLayoutまたはrecyclerViewを使用する必要がありますか?私はどちらも使用していないので、どちらも新しいものになります。 –

+0

繰り返しコードを書く必要がないため、私はRecyclerViewが良い選択肢かもしれないと思います。それを始める方法については、オンラインのチュートリアルがかなりあります。しかし、一言で言えば、データをアダプタに供給し、データを表示するはずのビューにデータをマップします。 RecyclerViewが複雑すぎる場合は、GridViewも参照してください。しかし、RecyclerViewの方が効率的であるため(ViewHolderパターン)、RecyclerViewを使用することをお勧めします。 – dungtatas

+0

あなたはこの回答を見ることができます:http://stackoverflow.com/questions/40587168/simple-android-grid-example-using-recyclerview-with-gridlayoutmanager-like-the – dungtatas

関連する問題