Android fading/dimming like menu option

2019-08-16 16:48发布

问题:

I have an layout with some icons. When i touch one icon on the bottom, in the 1/4 of the screen on the bottom wil become something like an option menu which I created myself.

My goal is to fade / dimm now the rest of the screen, except the 1/4 on the bottom. An also to make this part of the screen inactive, like for the optionMenu in android.

Do you have any idea how could I do this? Shuld I create two separate layouts, one with the icons and another with the menu?

Thank you.

Here Is ma initial layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg" >


 <RelativeLayout
     android:id="@+id/mainRelativeLayout"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentLeft="true"
     android:layout_alignParentRight="true"
     android:layout_alignParentTop="true"
     android:layout_marginLeft="10dp"
     android:layout_marginTop="10dp" >

     <TextView
         android:id="@+id/CenterTextViewJournals"
         android:layout_width="wrap_content"
         android:layout_height="20dp"
         android:layout_centerHorizontal="true"
         android:layout_centerVertical="true"
         android:text="         " />

     <ImageView
         android:id="@+id/invisibleImageView"
         android:layout_width="120dp"
         android:layout_height="120dp"
         android:layout_centerHorizontal="true"
         android:layout_centerVertical="true" />

     <ImageView
         android:id="@+id/EditorialBoard"
         android:layout_width="120dp"
         android:layout_height="120dp"
         android:layout_above="@+id/CenterTextViewJournals"
         android:layout_centerHorizontal="true"
         android:onClick="goEditorialBoard"
         android:src="@drawable/button_about_active" />

     <ImageView
         android:id="@+id/Contact"
         android:layout_width="120dp"
         android:layout_height="120dp"
         android:layout_alignBottom="@+id/CenterTextViewJournals"
         android:layout_toRightOf="@+id/CenterTextViewJournals"
         android:onClick="goContact"
         android:src="@drawable/button_about_active" />

     <ImageView
         android:id="@+id/AimsAndScope"
         android:layout_width="120dp"
         android:layout_height="120dp"
         android:layout_alignBottom="@+id/CenterTextViewJournals"
         android:layout_toLeftOf="@+id/CenterTextViewJournals"
         android:onClick="goAimsAndScope"
         android:src="@drawable/button_about_active" />

     <ImageView
         android:id="@+id/Articles"
         android:layout_width="180dp"
         android:layout_height="180dp"
         android:layout_centerHorizontal="true"
         android:layout_centerVertical="true"
         android:onClick="goArticles"
         android:paddingBottom="9px"
         android:paddingLeft="6px"
         android:paddingRight="8px"
         android:paddingTop="4px"
         android:src="@drawable/button_about_active" />

 </RelativeLayout>


<ImageView
    android:id="@+id/StartSelectingDifferentJournal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:scaleType="fitXY"
    android:src="@drawable/journal_selecting_barr" />

<Gallery
    android:id="@+id/gallery"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/SelectDifferentJournaleditText"
    android:layout_alignParentLeft="true"
    android:gravity="bottom" />

<EditText
    android:id="@+id/SelectDifferentJournaleditText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:visibility="gone"
    android:hint="Search Journal">
</EditText>

<ImageView
    android:id="@+id/SelectingDifferentJournal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/gallery"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:gravity="bottom"
    android:scaleType="fitXY"
    android:src="@drawable/journal_selecting_barr" />

回答1:

Alright, here's a simple way of doing this, but your going to have to modify your layout setup.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg" >


 <RelativeLayout
     android:id="@+id/mainRelativeLayout"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentLeft="true"
     android:layout_alignParentRight="true"
     android:layout_alignParentTop="true"
     android:layout_marginLeft="10dp"
     android:layout_marginTop="10dp" >

     <TextView
         android:id="@+id/CenterTextViewJournals"
         android:layout_width="wrap_content"
         android:layout_height="20dp"
         android:layout_centerHorizontal="true"
         android:layout_centerVertical="true"
         android:text="         " />

     <ImageView
         android:id="@+id/invisibleImageView"
         android:layout_width="120dp"
         android:layout_height="120dp"
         android:layout_centerHorizontal="true"
         android:layout_centerVertical="true" />

     <ImageView
         android:id="@+id/EditorialBoard"
         android:layout_width="120dp"
         android:layout_height="120dp"
         android:layout_above="@+id/CenterTextViewJournals"
         android:layout_centerHorizontal="true"
         android:onClick="goEditorialBoard"
         android:src="@drawable/button_about_active" />

     <ImageView
         android:id="@+id/Contact"
         android:layout_width="120dp"
         android:layout_height="120dp"
         android:layout_alignBottom="@+id/CenterTextViewJournals"
         android:layout_toRightOf="@+id/CenterTextViewJournals"
         android:onClick="goContact"
         android:src="@drawable/button_about_active" />

     <ImageView
         android:id="@+id/AimsAndScope"
         android:layout_width="120dp"
         android:layout_height="120dp"
         android:layout_alignBottom="@+id/CenterTextViewJournals"
         android:layout_toLeftOf="@+id/CenterTextViewJournals"
         android:onClick="goAimsAndScope"
         android:src="@drawable/button_about_active" />

     <ImageView
         android:id="@+id/Articles"
         android:layout_width="180dp"
         android:layout_height="180dp"
         android:layout_centerHorizontal="true"
         android:layout_centerVertical="true"
         android:onClick="goArticles"
         android:paddingBottom="9px"
         android:paddingLeft="6px"
         android:paddingRight="8px"
         android:paddingTop="4px"
         android:src="@drawable/button_about_active" />

 </RelativeLayout>


<ImageView
    android:id="@+id/StartSelectingDifferentJournal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:scaleType="fitXY"
    android:src="@drawable/journal_selecting_barr" />
</RelativeLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/dimmer_layout"/>
<RelativeLayout
    layout_width="match_parent"
    layout_height="match_parent">
<Gallery
    android:id="@+id/gallery"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/SelectDifferentJournaleditText"
    android:layout_alignParentLeft="true"
    android:gravity="bottom" />

<EditText
    android:id="@+id/SelectDifferentJournaleditText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:visibility="gone"
    android:hint="Search Journal">
</EditText>

<ImageView
    android:id="@+id/SelectingDifferentJournal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/gallery"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:gravity="bottom"
    android:scaleType="fitXY"
    android:src="@drawable/journal_selecting_barr" />
</RelativeLayout>
</FrameLayout>

When the menu gets opened, set the Linear Layout's background to a transparent black like 0x55000000.

void onMenuOpen() {
    openTheMenu();
    LinearLayout llDimmer = (LinearLayout)findViewById(R.id.dimming_layout);
    llDimmer.setBackgroundColor(0x55000000);
}

Then you can set the background color to 0x00000000 after the menu closes.



回答2:

You can use Popwindow to show option menu.