简体   繁体   中英

Unable to display the ImageView in FrameLayout (Android)

I had made a simple camera app and was thinking about customizing the view. Currently, I've been stuck with a problem with the ImageView not being able to be displayed on the top of the framelayout. Is there something wrong with the xml code below ? Or should I set some parameter in the code ? All I want to do is to display the Imageview above the framelayout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <FrameLayout
        android:id="@+id/camera_preview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        >

        <LinearLayout

            android:orientation="horizontal"

            android:layout_width="wrap_content"

            android:layout_height="match_parent"

            android:layout_gravity="right|center_vertical">
        <ImageView
            android:id="@+id/button_capture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/shot_dot_icn" />
            </LinearLayout>
    </FrameLayout>
</LinearLayout>

Try this layout, I am not sure if I understand your requirement though.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
        <ImageView
            android:id="@+id/button_capture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/shot_dot_icn" />
    <FrameLayout
        android:id="@+id/camera_preview"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        >

        <LinearLayout

            android:orientation="horizontal"

            android:layout_width="wrap_content"

            android:layout_height="match_parent"

            android:layout_gravity="right|center_vertical">
            </LinearLayout>
    </FrameLayout>
</LinearLayout>

I solved the problem with the script below. All I had to do was to set the bringToFront() to the ImageView to set the view on top of the Framelayout.

  ImageView captureButton = (ImageView) findViewById(R.id.button_capture);
        captureButton.bringToFront();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM