2013-10-14 15 views
0

我已经写了一个应用程序,现在想要设计UI。问题是我拥有相同的数据(好吧,不一样,但是因为它是一个XML读数,所以是同一种数据),现在我想要设计它。但我不认为我可以通过编程获得设计。所以我认为我使用XML来设计一次,然后在for循环中为其他数据复制布局。这可能吗?多次使用一个listview的XML设计

如果是,那怎么可能?我现在完成了一个条目的XML,现在我希望所有其他条目都具有与其他条目相同的样式和布局......谢谢!

+0

你读过如何使用一个ListView与自定义单元格?点10 http://www.vogella.com/articles/AndroidListView/article.html –

+0

听起来很有趣。我会试一试。谢谢。将报告回来,但我有很多数据,所以需要一些时间。已经感觉到了! – Musterknabe

回答

0

有一个简单的方法来实现这一点。

在xml文件中包含标签,您可以在多个屏幕设计中使用一种布局。

例如。你为应用程序创建了头文件,因此不需要在所有文件中使用相同的代码,只需在每个xml文件中包含该部分即可。

这里是一个简单的例子,可以帮助你。

创建一个可重用的布局

titlebar.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width=”match_parent” 
    android:layout_height="wrap_content" 
    android:background="@color/titlebar_bg"> 

    <ImageView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/gafricalogo" /> 
</FrameLayout> 

使用标签:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width=”match_parent” 
    android:layout_height=”match_parent” 
    android:background="@color/app_bg" 
    android:gravity="center_horizontal"> 

    <include layout="@layout/titlebar"/> 

    <TextView android:layout_width=”match_parent” 
       android:layout_height="wrap_content" 
       android:text="@string/hello" 
       android:padding="10dp" /> 

    ... 

</LinearLayout> 
+0

嘿谢谢,但我想你误解了我的问题。我不想在我的新布局中使用其他布局。我只想设计一次TextView,然后以编程方式将其用于下一个48。我的回答下面的评论帮了我一些。我会尝试一下。 – Musterknabe

+0

okey然后你可以创建自定义的类,这是通过textview或函数来扩展的,用它的样式创建文本视图。 – Hasmukh