![](/img/trans.png)
[英]how to show different Numbers of columns in a single listview in portrait and landscape mode android?
[英]Single column ListView in Portrait but Two columns in Landscape?
我正在创建一个显示“电话联系人”的列表。 它可以工作,但由于横向拉伸而看起来不佳。
因此,我决定在“风景”中将其设为两列, 在“肖像” 中将其设为一列 。 我似乎无法通过谷歌搜索找到任何参考。
有什么办法吗? 如果我只需要将自定义XML放在layout-land
文件夹中,那就太好了
谢谢
[UPDATE]
在Portrait中,它将是这样的:
name 1
name 2
name 3
name 4
在风景中:
name 1 name 2
name 3 name 4
查看Fragment
的http://developer.android.com/training/basics/fragments/index.html
基本上,就像您建议的那样,您将有两个布局文件夹。
您将把界面构建到Fragment
,并将其中两个放置在风景中,一个放置在肖像中。 例如
public class ContactListFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.contact_list, container, false);
// do your work
return view;
}
}
public class MainActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// configure your fragments here.
}
}
res \\ Layout \\ main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.example.android.fragments.ContactListFragment"
android:id="@+id/contact_list_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
res \\ layout-land \\ main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.example.android.fragments.ContactListFragment"
android:id="@+id/contact_list_fragment1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.example.android.fragments.ContactListFragment"
android:id="@+id/contact_list_fragment2"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
您应该已经使用了GridView。 根据方向将numColumns字段更改为1或2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.