두 개의 LinearLayouts가 작동하지 않고 layout_weight를 사용하여 동일한 높이를 갖도록하십시오.

다니엘 고베

이 두 LinearLayouts가 동일한 높이를 갖도록 단일 LinearLayout에 중첩되는 데 어려움이 있습니다. 첫 번째 LinearLayout은 높이가 0이고 두 번째는 전체 화면을 차지합니다.

중요한지 확실하지 않지만 두 번째 LinearLayout을 버튼으로 프로그래밍 방식으로 채 웁니다.

XML

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.yako.mimibot.pages.RemoteCtrlFragment">

    <LinearLayout
        android:id="@+id/remote_ctrl_ll"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="2">

        <LinearLayout
            android:id="@+id/terminal_ll"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/terminal_window">
            <ScrollView
                android:id="@+id/terminal_scroll"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <RelativeLayout
                    android:id="@+id/terminal_rl"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                </RelativeLayout>
            </ScrollView>
        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:id="@+id/remote_gesture_btns_ll"
            android:gravity="center">
        </LinearLayout>
    </LinearLayout>

</FrameLayout>

두 번째 LinLay를 채우기위한 코드 (R.id.remote_gesture_btns_ll)

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_remote_ctrl, container, false);

        mRemoteGestureBtnsLL = (LinearLayout) view.findViewById(R.id.remote_gesture_btns_ll);
        mTerminalRL = (RelativeLayout) view.findViewById(R.id.terminal_rl);

        String[] mimiGestures = getActivity().getResources().getStringArray(R.array.mimi_capable_gestures_array);

        LinearLayout mimiBtnsLL = null;
        Button mimiBtn;
        for (int i=0; i < mimiGestures.length; i++) {
            if (i%2 == 0) {
                mimiBtnsLL = new LinearLayout(getActivity());
                mimiBtnsLL.setOrientation(LinearLayout.HORIZONTAL);
                mimiBtnsLL.setGravity(Gravity.CENTER_HORIZONTAL);
                mimiBtnsLL.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            }

            mimiBtn = new Button(getActivity());
            mimiBtn.setText(mimiGestures[i]);
            mimiBtn.setHeight(100);
            mimiBtn.setWidth(200);
            mimiBtn.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            mimiBtnsLL.addView(mimiBtn);

            if (i%2 == 1) {
                mRemoteGestureBtnsLL.addView(mimiBtnsLL);
            }
        }

        return view;
    }
shhp

부모의 높이 LinearLayout(id 포함 remote_ctrl_ll)를로 설정하십시오 match_parent.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관