简体   繁体   English

如何在纵向和横向模式的android中的单个listview中显示不同的列数?

[英]how to show different Numbers of columns in a single listview in portrait and landscape mode android?

can any one tell me it is possible to show different number of columns in listview 谁能告诉我在列表视图中可以显示不同数量的列吗

For Example:- when i see listview in portrait mode it shows 3 columns and when i see listview in landscape mode it shows 4 columns . 例如:-当我在纵向模式下看到列表视图时,它显示3列,而当我在横向模式下看到列表视图时,它显示4列。 i try to do it but my solutions doesn't work for me , i define to different layout for protrait in layout folder and landscape in layout-land folder but it doesn't seens to work for me . 我尝试这样做,但是我的解决方案对我不起作用,我在布局文件夹中为protrait定义了不同的布局,在布局-土地文件夹中为景观定义了不同的布局,但是它似乎不适用于我。

Can any one tell me is it possible to achive this . 

And one More thing it possible to execute some code by checking 

For Example:-  if(this is android phone){

                  execute this code;
                 }

                if(this is android tablet){

                        execute this code;
                     }

 like iphone and ipad developer do 

                   if(this is iphone )
                   {
                    execute this code ;
                      }



                   if(this is ipad )
                   {
                    execute this code ;
                      }

because i same application is used in both phone and tablet and some one wants to show different things in phones and different in tablets . 因为我在手机和平​​板电脑上使用了相同的应用程序,有人希望在手机和平​​板电脑上显示不同的事物。

Thanks in advance

Try this below link for tutorial 尝试以下链接以获取教程

http://www.technotalkative.com/android-multi-column-listview/ http://www.technotalkative.com/android-multi-column-listview/

Thanks..! 谢谢..!

 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
 int width = metrics.widthPixels;
 int height = metrics.heightPixels;

this gives the dimensions of the screen and based on these values you can determine if it is a tablet.. See this link to know how to get dimensions of your device 这给出了屏幕的尺寸,并根据这些值可以确定它是否是平板电脑。 请参阅此链接以了解如何获取设备的尺寸

Create more layouts with same name in /res/layout 在/ res / layout中创建更多具有相同名称的布局

After selecting root element click "Next" and then choose one of the Available qualifiers (orientation) and define listView with its properties. 选择根元素后,单击“下一步”,然后选择“可用”限定词(方向)并定义listView及其属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM