Estoy tratando de agregar un fragmento programáticamente a LinearLayout, pero el fragmento no extiende su contenido en toda la altura de los diseños. Actúa como wrap_content en lugar de fill_parent.Android 3 - Agregar un fragmento a LinearLayout: fill_parent no funciona
En el otro lado, fill_parent trabaja en el ancho del fragmento. ¿Cómo puedo cambiar este comportamiento?
DashboardActivity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<fragment
android:id="@+id/fragment_dashboard"
android:layout_width="5dp"
android:layout_height="fill_parent"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:name="de.upb.cs.ginkgo.tablet.ui.fragments.DashboardFragment" >
<!-- Preview: [email protected]/fragment_dashboard -->
</fragment>
<LinearLayout
android:id="@+id/rightfrag"
android:layout_width="450dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:layout_marginBottom="15dp"
android:layout_marginRight="10dp" >
</LinearLayout>
</LinearLayout>
Su método onCreate:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
//-- Instantiate Fragmentstuff
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ActivitystreamFragment asf = new ActivitystreamFragment();
fragmentTransaction.add(R.id.rightfrag, asf);
fragmentTransaction.commit();
}
El XML ActivitystreamFragment:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<ListView
android:id="@+id/android:list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawSelectorOnTop="true"
android:background="@drawable/back_rightfrag"
>
</ListView>
</LinearLayout>
Y su createView:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_activitystream, null);
return root;
}
Gracias. Pero no sé por qué el FrameLayout funciona, pero LinearLayout doen't –
¿Intentó poner el FrameLayout * dentro * del LinearLayout? – zmbq
@NguyenMinhBinh: Debido a que FrameLayout pone a sus hijos uno encima del otro, un LinearLayout por otro lado pone a sus hijos al lado (horizontal o verticalmente) el uno al otro. Las transiciones funcionan, pero el Fragmento recién agregado está fuera de la pantalla. – Kuno