I am trying to create a splitView in Android programmatically. This feature is completely new to me. After some research, I realized the Fragment has to be used.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.example.news.ArticleListFragment"
android:id="@+id/list"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.example.news.ArticleReaderFragment"
android:id="@+id/viewer"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
I am wondering, is the LinearLayout the best option for a layout? Secondly is it possible to add UI parts like buttons, pickers onto the fragment programmatically as well?
You can use any layout with Fragments, totally depends on your requirement.
Yes you can add views like Buttons etc to Fragment programmatically. Declare the layout of the Fragment to be a Layout.
One example of adding views programmatically — R.layout.main could be a LinearLayout with no child views