2014-01-29 102 views
4

我上的应用程序会从SD卡获取图像,将分别展示他们在这样添加布局progamatically安卓

enter image description here

The Issue is: 

布局工作比方说用户有100+ SD卡中的文件,在布局中显示我需要添加前100 +视图,然后我会做的样式。 Wrong approach

My Question is: 

什么可以做任何progamatically或通过XML,这样我可以只定义了五种基本观点和根据在SD卡图像的数量,它创造的剩余布局和视图,这样我可以通过水平滚动视图访问它们。

My research includes: 

我尝试使用网格视图布局,但它并没有完全满足我的需求,因为它有所有网格的大小均匀。更多我知道如何以编程方式添加布局,但我不知道如何使其与我的设计一起工作。

任何帮助,将不胜感激

+0

你可以使用gridview或交错gridview https://github.com/etsy/AndroidStaggeredGrid – Raghunandan

+0

你可以在horizo​​ntalScrollView中使用gridlayout,加载一个或多个文件,并在用户滚动到最后时加载更多内容。 – Ayoub

回答

1

你可以通过改变你xml的两侧滚动原样

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="320px" android:layout_height="fill_parent"> 

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/linlay" android:layout_width="320px" 
     android:layout_height="fill_parent" android:stretchColumns="1" 
     android:background="#000000"/> 

</HorizontalScrollView> 

0

使用这种方法,使其: -

1.)将路径放置在数组列表中的所有图像上。

2.)创建一个for循环,它将运行到arraylist的大小。

3.)在此循环中,使用代码创建您的imageview。

ImageView im = new ImageView(this); 

4.)要显示图像,请在src属性中添加来自arraylist的路径。

您需要使用一些额外的布局参数来根据您的需要进行设计。

+0

我需要定义每个图像相对于另一个的相关性,那么我们将如何管理它? –

+0

为此,您需要为不同的属性创建不同的数组列表,并且对于no的imageview,调用与x arraylist中的属性相关的属性。 – Payal