13
단편을 프로그래밍 방식으로 LinearLayout에 추가하려고하지만 조각이 전체 레이아웃 높이에 걸쳐 내용을 늘리지 않습니다. fill_parent 대신 wrap_content와 같은 역할을합니다.Android 3 - LinearLayout에 단편 추가 : fill_parent가 작동하지 않습니다.
반면에 fill_parent는 조각의 너비에서 작동합니다. 이 동작을 어떻게 변경합니까?
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: layout=[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>
그것에서 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();
}
ActivitystreamFragment의 XML :
<?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>
그리고 그 createView :
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_activitystream, null);
return root;
}
감사합니다. 하지만 FrameLayout이 작동하지만 LinearLayout이 작동하지 않는 이유를 모르겠습니다. –
LinearLayout 내부에 FrameLayout *을 넣으려고 했습니까? – zmbq
@NguyenMinhBinh : FrameLayout은 그 아이를 서로 겹쳐 놓기 때문에, LinearLayout은 아이를 다음 (수평 방향 또는 수직 방향)으로 서로 붙입니다. 화면 전환은 작동하지만 새로 추가 된 화면은 화면 외부에 있습니다. – Kuno