![](/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.