SlideMenuLayout слайд не только макет, но и деятельность - PullRequest
0 голосов
/ 06 ноября 2018

Здравствуйте! Мне удалось воспроизвести код из этого урока https://www.youtube.com/watch?v=HrLLnoa9Zd4&index=32&list=WL&t=330s.

Но затем я решил добавить что-то простое, например кнопку, на левый слайд, которая меняет его текст. Я создал новое действие с SetContentView(Resource.Layout.Left); и записал событие click для кнопки. Когда я запускаю программу, я нажимаю на кнопку, и ничего не происходит. Я понял, что на самом деле это действие не называется, и я вижу только макет.

У меня вопрос: есть ли способ вызвать действие, которое я написал, когда я сдвигаюсь влево?

основной макет

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.jkb.slidemenu.SlideMenuLayout
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/slideMenuLayout1"
    app:contentToggle="true"
    app:contentAlpha="0.5"
    app:parallax="false"
    app:slideMode="both">

    <include layout="@layout/Left" />
    <include layout="@layout/Right" />
    <include layout="@layout/MainView" />   

  </com.jkb.slidemenu.SlideMenuLayout>
</RelativeLayout>  

левый макет

<Button
    android:text="Button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/leftBtn" />
<TextView
    android:text="Slide Left"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minWidth="25px"
    android:minHeight="25px"
    android:id="@+id/leftText" />  

левая деятельность

Button btn = FindViewById<Button>(Resource.Id.leftBtn);
TextView text = FindViewById<TextView>(Resource.Id.leftText);
btn.Click += (sender, e) => { text.Text = "text is chaged"; };

Ответы [ 2 ]

0 голосов
/ 08 ноября 2018

Я получил. Я могу использовать fragments вместо include.
Файл main.axml будет выглядеть так

<com.jkb.slidemenu.SlideMenuLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/slideMenuLayout1"
app:contentToggle="true"
app:contentAlpha="0.5"
app:parallax="false"
app:slideMode="both">

   <fragment
    class="NameSpace.FragmentName"  //it is important to write the namespace and gragment name
    android:layout = "@layout/Left" //here you choose the layout you want to render
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/RightFragment" />

      //repeat the same for the Right and Main view 

</com.jkb.slidemenu.SlideMenuLayout>  

А фрагмент.cs тебе просто нужен

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
         base.OnCreateView(inflater, container, savedInstanceState);

          View  view = inflater.Inflate(Resource.Layout.YourLayout, container, false);
    }
0 голосов
/ 07 ноября 2018

Я делаю одну демонстрацию об использовании SlideMenuLayout, но я не могу воспроизвести вашу проблему, и я могу изменить текст кнопки представления content_menu_left, вот мой пример:

main.axml:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" 
android:orientation="vertical"  
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.jkb.slidemenu.SlideMenuLayout 
    android:id="@+id/mainSlidemenu"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    app:contentAlpha="0.5" 
    app:contentToggle="true" 
    app:parallax="false" 
    app:slideMode="both">

    <include layout="@layout/content_menu_left"/>
    <include layout="@layout/content_menu_right"/>
    <TextView                   
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="this is slide menu main layout" 
        android:textSize="22sp" />  

    </com.jkb.slidemenu.SlideMenuLayout>
</LinearLayout>

левое меню:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="left menu" 
    android:textSize="22sp" />

<Button 
    android:id="@+id/btn1" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:text="left menu" />
</LinearLayout>
Button button1;
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        // Set our view from the "main" layout resource
        //SetContentView(Resource.Layout.activity_main);
        SetContentView(Resource.Layout.activity_main);

        button1 = (Button)FindViewById(Resource.Id.btn1);
        button1.Click += Button1_Click;
    }

    private void Button1_Click(object sender, System.EventArgs e)
    {
        button1.Text = "this is test";
    }
...