我想向MainActivity添加一個片段,但是當我爲它添加一個fragmnet時,它覆蓋了主要活動的全部寬度和高度。因此,如何設置片段的寬度和高度以編程方式包裝內容,而不是使用XML。如何以編程方式添加片段的寬度和高度?
這裏是我到目前爲止做的代碼:
MainActivity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/rekl"
android:layout_height="match_parent"
tools:context="com.example.ankit.fragment2.MainActivity">
</RelativeLayout>
MainActivity.java
設置R.id.rekl上的寬度和高度。 –
顯示您的活動xml –