Reputation: 4464
I'm making a list that display Phone Contact. It works but does not looks good in Landscape orientation since it just stretched out.
So I decided to make it two column while in Landscape and one column in Portrait. I can't seem to find any reference by googling.
Is there any way to do it? It would be great if I just need to put custom XML in layout-land
folder
Thanks
[UPDATE]
In Portrait it will be like this:
name 1
name 2
name 3
name 4
In Landscape:
name 1 name 2
name 3 name 4
Upvotes: 1
Views: 3091
Reputation: 2725
You should have used a GridView. Depending on the orientation change the numColumns field to 1 or 2.
Upvotes: 0
Reputation: 16245
Look into Fragment
s http://developer.android.com/training/basics/fragments/index.html
Basically you will have two layout folders for this, just like you suggested.
You'll build your interface into Fragment
s and place two of them in the landscape and one in portrait. For example
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>
Upvotes: 1