0
我想在屏幕底部放置一個簡單的單個網格。這裏是理想的結果的屏幕截圖android桌面佈局 - 簡單實例
這將是冷靜,如果我能做出的「窗口」,顯示矩陣只有3行高,並允許用戶滾動/通過它。這樣,當屏幕旋轉時,列表/矩陣不會在水平模式下佔用整個屏幕。
我懷疑我應該使用表格佈局?以下是我的activity_main.xml。我想用包含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>
非常感謝。我的數據不會超過20行,4列寬。這不是很大,但有線條的網格會讓閱讀更容易。我希望它能夠適合我的屏幕底部,同時我已將文本視圖保存在我的應用中......頂部。我應該使用tableLayout還是recyclerView?既然我沒有用過,他們對我來說都是新生事物。 –
爲了不必重複編寫代碼,我認爲RecyclerView可能是更好的選擇。網上有很多關於如何開始使用它的教程。但簡而言之,您將數據提供給適配器,該適配器將數據映射到應該顯示的視圖。如果你發現RecyclerView太複雜,你也可以看看GridView。但是,嘗試使用RecyclerView是一種很好的做法,因爲它更高效(ViewHolder模式)。 – dungtatas
你可以看看這個答案:http://stackoverflow.com/questions/40587168/simple-android-grid-example-using-recyclerview-with-gridlayoutmanager-like-the – dungtatas