SORU
21 Ocak 2010, PERŞEMBE


Nasıl Android kenarlıklı bir tablo oluşturabilir miyim?

Tablo olarak verileri görüntülemek için bir tablo düzeni kullanıyorum ama sınırları ile kullanıcı tanımlı sütunlar ve satırlar ile bir masa istiyorum. Öneriniz var mı?

CEVAP
11 EYLÜL 2011, Pazar


Bu sorun için çözüm her hücrenin arka plan sahada xml drawable bir kaynak koymaktır. Bu şekilde tüm hücreler için istediğiniz kenarlık şekli tanımlayabilirsiniz. Tek sıkıntı aşırı hücre sınırları, diğer yarısı genişliği var ama tabloya tüm ekranı doldurur sorun değil.

Bir Örnek:

drawable/cell_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
  xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape= "rectangle"  >
        <solid android:color="#000"/>
        <stroke android:width="1dp"  android:color="#ff9"/>
</shape>

layout/my_table.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
            <TableRow android:id="@ id/tabla_cabecera" android:layout_width="match_parent" android:layout_height="match_parent"></TableRow>
            <TableLayout android:id="@ id/tabla_cuerpo" android:layout_height="match_parent" android:layout_width="match_parent">
                <TableRow android:id="@ id/tableRow1" android:layout_width="match_parent" android:layout_height="wrap_content">

                    <TextView android:background="@drawable/cell_shape" android:padding="5dp" android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
                    <TextView android:background="@drawable/cell_shape" android:padding="5dp" android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
                    <TextView android:background="@drawable/cell_shape" android:padding="5dp" android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>

                </TableRow>
                <TableRow android:id="@ id/tableRow2" android:layout_width="match_parent" android:layout_height="wrap_content">                    

                    <TextView android:background="@drawable/cell_shape" android:padding="5dp" android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
                    <TextView android:background="@drawable/cell_shape" android:padding="5dp" android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
                    <TextView android:background="@drawable/cell_shape" android:padding="5dp" android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView></TableRow>

                <TableRow android:id="@ id/tableRow3" android:layout_width="match_parent" android:layout_height="wrap_content">                    

                    <TextView  android:background="@drawable/cell_shape" android:padding="5dp" android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
                    <TextView android:background="@drawable/cell_shape" android:padding="5dp" android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
                    <TextView android:background="@drawable/cell_shape" android:padding="5dp" android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>

                </TableRow>
                <TableRow android:id="@ id/tableRow4" android:layout_width="match_parent" android:layout_height="wrap_content">                    

                    <TextView android:background="@drawable/cell_shape" android:padding="5dp" android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
                    <TextView android:background="@drawable/cell_shape" android:padding="5dp" android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
                    <TextView  android:background="@drawable/cell_shape" android:padding="5dp" android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>

                </TableRow>
            </TableLayout>


</LinearLayout>

Edit: Bir örnek

enter image description here

Edit2: Başka bir örnek (daha fazla öğe: yuvarlak köşeler, geçişlerini...) enter image description here

http://blog.intelligenia.com/2012/02/programacion-movil-en-android.html#more Daha fazla ayrıntı ile bu sorunu açıkladım. İspanyolca değil ama daha karmaşık bazı tabloların kodları ve görüntüleri vardır.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Leigh Momii

    Leigh Momii

    10 Mayıs 2006
  • LounaTutorials

    LounaTutoria

    10 EYLÜL 2009
  • TurkishRoyal

    TurkishRoyal

    16 Ocak 2007