Android 如何在布局中替换或添加大视图

Android 如何在布局中替换或添加大视图,android,android-fragments,android-tablelayout,Android,Android Fragments,Android Tablelayout,我使用TableLayout成功创建了自定义数字键盘 这是来源 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/blac

我使用TableLayout成功创建了自定义数字键盘

这是来源

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black"
android:clickable="true">



<TableLayout
    android:id="@+id/keyboard_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="#e5e5e5" />


    <TableRow
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">


        <Button
            android:id="@+id/keyboard_one"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:background="@null"
            android:clickable="true"
            android:gravity="center"
            android:text="1"
            android:textColor="#4d4d4d"
            android:textSize="@dimen/u_common_text_size_medium_large"
            />

        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="#e5e5e5" />


        <Button
            android:id="@+id/keyboard_two"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:background="@null"
            android:clickable="true"
            android:gravity="center"
            android:text="2"
            android:textColor="#4d4d4d"
            android:textSize="@dimen/u_common_text_size_medium_large"

            />

        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="#e5e5e5" />


        <Button
            android:id="@+id/keyboard_three"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:background="@null"
            android:clickable="true"
            android:gravity="center"
            android:text="3"
            android:textColor="#4d4d4d"
            android:textSize="@dimen/u_common_text_size_medium_large"

            />

    </TableRow>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="#e5e5e5" />


    <TableRow
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">


        <Button
            android:id="@+id/keyboard_four"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:background="@null"
            android:clickable="true"
            android:gravity="center"
            android:text="4"
            android:textColor="#4d4d4d"
            android:textSize="@dimen/u_common_text_size_medium_large"


            />

        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="#e5e5e5" />


        <Button
            android:id="@+id/keyboard_five"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:background="@null"
            android:clickable="true"
            android:gravity="center"
            android:text="5"
            android:textColor="#4d4d4d"
            android:textSize="@dimen/u_common_text_size_medium_large"


            />

        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="#e5e5e5" />


        <Button
            android:id="@+id/keyboard_six"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:background="@null"
            android:clickable="true"
            android:gravity="center"
            android:text="6"
            android:textColor="#4d4d4d"
            android:textSize="@dimen/u_common_text_size_medium_large"


            />
    </TableRow>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="#e5e5e5" />


    <TableRow
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">


        <Button
            android:id="@+id/keyboard_seven"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:background="@null"
            android:clickable="true"
            android:gravity="center"
            android:text="7"
            android:textColor="#4d4d4d"
            android:textSize="@dimen/u_common_text_size_medium_large"

            />

        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="#e5e5e5" />


        <Button
            android:id="@+id/keyboard_eight"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:background="@null"
            android:clickable="true"
            android:gravity="center"
            android:text="8"
            android:textColor="#4d4d4d"
            android:textSize="@dimen/u_common_text_size_medium_large"


            />

        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="#e5e5e5" />


        <Button
            android:id="@+id/keyboard_nine"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:background="@null"
            android:clickable="true"
            android:gravity="center"
            android:text="9"
            android:textColor="#4d4d4d"
            android:textSize="@dimen/u_common_text_size_medium_large"


            />

    </TableRow>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="#e5e5e5" />


    <TableRow
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">


        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:gravity="center">

            <Button
                android:id="@+id/keyboard_dot"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@null"
                android:clickable="true"
                android:gravity="center"
                android:text="."
                android:textColor="#ffffff"
                android:textSize="@dimen/u_common_text_size_medium_large"

                android:visibility="gone" />

            <ImageView
                android:id="@+id/keyboard_left"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:scaleType="fitCenter"
                android:src="@drawable/ic_fingerprint_white"
                android:visibility="invisible" />
        </RelativeLayout>

        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="#e5e5e5" />


        <Button
            android:id="@+id/keyboard_zero"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:background="@null"
            android:clickable="true"
            android:gravity="center"
            android:text="0"
            android:textColor="#4d4d4d"
            android:textSize="@dimen/u_common_text_size_medium_large"

            />


        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="#e5e5e5" />


        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:gravity="center">

            <ImageView
                android:id="@+id/keyboard_right"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:scaleType="fitCenter" />
        </LinearLayout>

    </TableRow>
</TableLayout>
我有一个问题。我的替换功能冻结了某些设备的屏幕。 我的问题是这是一个正确的解决方案吗?我怎样才能解决我的问题? 附笔
我的主要类也是Fragment,而不是Activity

您是只创建了一次Fragment还是每次替换都创建了Fragment?更好的方法是让它扩展视图,而不是使用片段。你可以在父布局中添加完整的布局内部标记,并在每次我尝试时隐藏其可见性,但问题是相同的。在我的情况下,当我尝试替换键盘碎片的布局不可见时,单击按钮,我试着用top_up和rimation@rafsanahmad007I第一次替换了碎片,这是什么意思?你能解释更多吗?@trunghieui的意思是你应该只替换一次,然后使用可见性显示或隐藏。
 public static void replace(FragmentManager fm, Fragment fragment, int container) {
    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(container, fragment);
    ft.commit();
}