Как показывать кнопки над окном просмотра

У меня есть пейджер, в котором каждый фрагмент имеет видеопросмотр. Теперь я хочу показать кнопки над этим пейджером. Для этого я использую макет фрейма. но по-прежнему не может сделать эти кнопки видимыми на обзорном пейджере. видны только фрагменты в моем пейджере просмотра, но кнопки, которые я хочу показать на пейджере просмотра, не становятся видимыми. когда в это время начинается активность, кнопки отображаются в течение 2,3 секунды, когда как только видео во фрагменте становится видимым, кнопки не видны

<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 = "wrap_content"
    xmlns:custom = "http://schemas.android.com/apk/res-auto"
    tools:context = ".Activities.MenuButtonActivity">


    <com.abp.app.ViewPager.NonSwipeableViewPager
        android:id = "@+id/viewpager"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"/>

    <RelativeLayout
        android:id = "@+id/rl_bottom_overlay"
        android:layout_width = "fill_parent"
        android:layout_height = "wrap_content"
        android:layout_gravity = "bottom"
        android:text = "yyyyyyyy"
        android:visibility = "visible" >

        <Button
            android:id = "@+id/btn_left_arrow"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:layout_alignParentLeft = "true"
            android:layout_centerVertical = "true"
            android:layout_marginLeft = "35dp"
            android:text = "yyyyyyyy" />

        <Button
            android:id = "@+id/btn_below_share"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:layout_alignParentRight = "true"
            android:layout_centerVertical = "true"
            android:layout_marginRight = "35dp"
            android:text = "yyyyyyyy"
            android:visibility = "visible" />

        <Button
            android:id = "@+id/btn_right_arrow"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:layout_centerHorizontal = "true"
            android:layout_centerVertical = "true"
            android:layout_marginLeft = "50dp"
            android:text = "yyyyyyyy"
            android:layout_toRightOf = "@id/btn_left_arrow" />
    </RelativeLayout>




     </FrameLayout>

вот код активности

package com.abp.app.Activities;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.abp.app.Adapter.MyPageAdapter;
import com.abp.app.CallerFuntionClasses.FunctionsCallApiFromServer;
import com.abp.app.Fragments.ConnectivityFragment;
import com.abp.app.Fragments.LondonRoyalDocksFragment;
import com.abp.app.Fragments.MasterPlanFragment;
import com.abp.app.Fragments.OfficesFragment;
import com.abp.app.Fragments.ProjectTeamFragment;
import com.abp.app.Fragments.VideosFragment;
import com.abp.app.R;
import com.abp.app.Utilities.AppVeriableClass;
import com.abp.app.Utilities.CustomSharePreferences;
import com.abp.app.Utilities.UtilsForDownloadDataFromServer;
import com.abp.app.ViewPager.NonSwipeableViewPager;

import java.util.ArrayList;
import java.util.List;

import static android.widget.RelativeLayout.ABOVE;

public class MenuButtonActivity extends AppCompatActivity {

    private Context context;
    private Activity activity;
    private int BtnHeight = 0;
    private ProgressBar progressBar;
    private TextView tv_progressCounting;
    private static String dirPath;
    boolean doubleBackToExit = false;
    FrameLayout frameLayout;
    RelativeLayout.LayoutParams params;
    FunctionsCallApiFromServer apiFromServer;
    String accessTokenType,accessToken;
    SharedPreferences sharedPreferences;
    CustomSharePreferences customSharePreferences = new CustomSharePreferences();
    ConnectivityManager conMgr;
    NetworkInfo netInfo;
    ArrayList<String> test;
    /////////////  Fragments //////////
    MasterPlanFragment masterPlanFragment ;
    OfficesFragment officesFragment;
    ConnectivityFragment connectivityFragment ;
    VideosFragment videosFragment ;
    LondonRoyalDocksFragment londonRoyalDocksFragment;
    ProjectTeamFragment projectTeamFragment ;

    MyPageAdapter pageAdapter;
    com.abp.app.ViewPager.NonSwipeableViewPager viewpager;

    ////////////////////////////////////
    private android.support.v4.app.FragmentTransaction fragmentTransaction;
    final Handler handler = new Handler();

    private static final int[] menuBtnIdsArray = {R.id.btn_masterplan,R.id.btn_Offices,R.id.btn_connectivity,R.id.btn_londonroyaldock,R.id.btn_videos,R.id.btn_projectteam};

    private ArrayList<Button> menuBtnArrayList = new ArrayList<Button>();

    private int previousClickedButton = 0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manu_buttons);
        viewpager = (com.abp.app.ViewPager.NonSwipeableViewPager)findViewById(R.id.viewpager);
        viewpager.setPagingEnabled(false);



        List fragments = getFragmetns();
        pageAdapter = new  MyPageAdapter( getSupportFragmentManager(),getFragmetns());
        viewpager.setAdapter(pageAdapter);


        VariableInitialize();
//        CallAPIFromServer();
        hideStatusBar();
       // onclickBtnFrangment();
       // firstTimeAlwaysCallFragment();
    }

    private void firstTimeAlwaysCallFragment() {
        frameLayout.setLayoutParams(new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT));
        setFragment(masterPlanFragment);
        menuBtnArrayList.get(0).setBackgroundColor(menuBtnArrayList.get(0).getContext().getResources().getColor(R.color.button_pressed));
    }

    private void VariableInitialize(){
        context = MenuButtonActivity.this;
        activity = MenuButtonActivity.this;

        ////////////// Fragment Initialize/////////////////
        masterPlanFragment = new MasterPlanFragment();
        officesFragment = new OfficesFragment();
        connectivityFragment = new ConnectivityFragment();
        londonRoyalDocksFragment = new LondonRoyalDocksFragment();
        videosFragment = new VideosFragment();
        projectTeamFragment = new ProjectTeamFragment();
        ////////////////////////////////
        conMgr =  (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        netInfo= conMgr.getActiveNetworkInfo();
        apiFromServer = new FunctionsCallApiFromServer();
        sharedPreferences = context.getSharedPreferences("AccessToken",Context.MODE_PRIVATE);
        accessToken = sharedPreferences.getString("Token",null);
        accessTokenType = sharedPreferences.getString("Type",null);
        dirPath = UtilsForDownloadDataFromServer.getRootDirPath(getApplicationContext());
       // frameLayout = (FrameLayout)findViewById(R.id.mainContainter_fragment);
        params = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT);
        //tv_progressCounting = (TextView)findViewById(R.id.textViewProgressCount);
        //progressBar = (ProgressBar)findViewById(R.id.progressbar);
    }


    private void onclickBtnFrangment(){
        for (int i = 0; i< menuBtnIdsArray.length; i++){
            final int currentBtnSelected = i;
            menuBtnArrayList.add((Button)findViewById( menuBtnIdsArray[i]));
            try {
                menuBtnArrayList.get(currentBtnSelected).setText(AppVeriableClass.getInstance().menuDisplayNames.get(i));

            } catch (Exception e) {
                e.printStackTrace();
            }
            menuBtnArrayList.get(i).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    switch (menuBtnArrayList.get(currentBtnSelected).getId()) {
                        case R.id.btn_masterplan:
                            setFragment(masterPlanFragment);
                            frameLayout.setLayoutParams(new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT));
                            selectedBtnColorChange(currentBtnSelected);

                            break;
                        case R.id.btn_Offices:
                            setFragment(officesFragment);
                            frameLayout.setLayoutParams(new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT));
                            selectedBtnColorChange(currentBtnSelected);

                            break;

                        case R.id.btn_connectivity:
                            setFragment(connectivityFragment);
                            frameLayout.setLayoutParams(new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT));// display full screen
                            selectedBtnColorChange(currentBtnSelected);

                            break;

                        case R.id.btn_londonroyaldock:
                            setFragment(londonRoyalDocksFragment);
                          //  params.addRule(ABOVE,R.id.linearlayout); // display show above on the menu bar as per the requirement.
                            frameLayout.setLayoutParams(params);
                            selectedBtnColorChange(currentBtnSelected);

                            break;
                        case R.id.btn_videos:
                            setFragment(videosFragment);
                           // params.addRule(ABOVE,R.id.linearlayout); // display show above on the menu bar as per the requirement.
                            frameLayout.setLayoutParams(params);
                            selectedBtnColorChange(currentBtnSelected);

                            break;
                        case R.id.btn_projectteam:
                            setFragment(projectTeamFragment);
                            frameLayout.setLayoutParams(new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT));
                            selectedBtnColorChange(currentBtnSelected);

                            break;
                    }
                }
            });
        }
    }
    // After click the menu button this function change the color of button until you press the other button.
    private void selectedBtnColorChange(int current) {
        menuBtnArrayList.get(previousClickedButton).setBackgroundColor(menuBtnArrayList.get(previousClickedButton).getContext().getResources().getColor(R.color.button_default));
        menuBtnArrayList.get(previousClickedButton).setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));
        menuBtnArrayList.get(current).setBackgroundColor(menuBtnArrayList.get(current).getContext().getResources().getColor(R.color.button_pressed));
        if (BtnHeight == menuBtnArrayList.get(current).getHeight()){
            LinearLayout.LayoutParams params = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, BtnHeight);
            menuBtnArrayList.get(current).setLayoutParams(params);
        }
        else{
            BtnHeight = menuBtnArrayList.get(current).getHeight() + 10;
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, BtnHeight);
            menuBtnArrayList.get(current).setLayoutParams(params);
        }
        previousClickedButton = current;
    }

    private void hideStatusBar(){
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }



    @Override
    public void onBackPressed(){

        if (doubleBackToExit){
            super.onBackPressed();
            return;
        }
        else
            Toast.makeText(context, "Click again to exit", Toast.LENGTH_SHORT).show();
        this.doubleBackToExit = true;


        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                doubleBackToExit = false;
            }
        },2000);
    }

    private void CallAPIFromServer(){
        if (netInfo != null) {
            apiFromServer.getMediaResourceOffices(context, activity, accessTokenType, accessToken);
            apiFromServer.getMediaResourceConnectivity(context, accessTokenType, accessToken);
            apiFromServer.getMediaResourceLondonRoyalDock(context, accessTokenType, accessToken);
            apiFromServer.getMediaResouceVideo(context, accessTokenType, accessToken);
        }

    }

    public void onResume() {
        super.onResume();
        conMgr =  (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
        netInfo= conMgr.getActiveNetworkInfo();
    }


    private void setFragment(Fragment fragment){
        fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.mainContainter_fragment,fragment);
        fragmentTransaction.commit();
    }

    private List<Fragment> getFragmetns()
    {
        List<Fragment> flist = new ArrayList<>();
        flist.add(MasterPlanFragment.NewIntance());
        flist.add(OfficesFragment.NewIntance());
        flist.add(ConnectivityFragment.NewIntance());
        flist.add(VideosFragment.NewIntance());
        flist.add(ProjectTeamFragment.NewIntance());


        return flist;
    }
}
2
0
308
1

Ответы 1

Попробуйте это решение.

<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 = ".Activities.MenuButtonActivity">

    <com.abp.app.ViewPager.NonSwipeableViewPager
        android:id = "@+id/viewpager"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"/>

    <LinearLayout
        android:id = "@+id/rl_bottom_overlay"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:layout_gravity = "bottom"
        android:orientation = "horizontal"
        android:text = "yyyyyyyy"
        android:visibility = "visible">

        <Button
            android:id = "@+id/btn_left_arrow"
            android:layout_width = "0dp"
            android:layout_height = "wrap_content"
            android:layout_weight = "1"
            android:text = "yyyyyyyy"/>

        <Button
            android:id = "@+id/btn_below_share"
            android:layout_width = "0dp"
            android:layout_height = "wrap_content"
            android:layout_weight = "1"
            android:text = "yyyyyyyy"
            android:visibility = "visible"/>

        <Button
            android:id = "@+id/btn_right_arrow"
            android:layout_width = "0dp"
            android:layout_height = "wrap_content"
            android:layout_weight = "1"
            android:text = "yyyyyyyy"/>
    </LinearLayout>

</FrameLayout>

И результат есть.

ваш код работает нормально при запуске, он показывает кнопку внизу, но как только фрагмент загружается в окно просмотра, кнопки снова становятся невидимыми

umair_aziz 18.09.2018 08:30

@umair_aziz, не могли бы вы выложить лог, что происходит при загрузке фрагмента. так что я могу понять.

Jaymin 18.09.2018 08:44

мой логарифм настолько длинный, что StackOverflow говорит, что вы не можете опубликовать более 3000 слов. что делать сейчас ?? могу я отправить его вам по электронной почте или другим способом.

umair_aziz 18.09.2018 09:01

Загрузите файл или укажите ссылку.

Jaymin 18.09.2018 09:02

Вы встречали какое-либо решение для этого?

umair_aziz 18.09.2018 09:22

Не удалось скачать файл. Сделай одно дело. отладьте свое приложение и выясните, в чем причина.

Jaymin 18.09.2018 09:22

вот ссылка отсюда вы можете легко скачать ufile.io/mzwc3 на самом деле я много пробовал, но не смог уловить проблему, зачем нужна ваша битовая помощь

umair_aziz 18.09.2018 09:28

Другие вопросы по теме