Android 如何为所有活动使用相同的SlideingPanel
上面是我在主要活动中使用的SlidingUpPanel的XML代码。它有两个部分,主要内容(普通屏幕)和滑动内容(来自屏幕底部)。现在的问题是,此面板将仅显示在主活动中。我想显示所有活动的面板。请指导我如何进行 请帮忙Android 如何为所有活动使用相同的SlideingPanel,android,android-layout,android-activity,drawerlayout,slidingdrawer,Android,Android Layout,Android Activity,Drawerlayout,Slidingdrawer,上面是我在主要活动中使用的SlidingUpPanel的XML代码。它有两个部分,主要内容(普通屏幕)和滑动内容(来自屏幕底部)。现在的问题是,此面板将仅显示在主活动中。我想显示所有活动的面板。请指导我如何进行 请帮忙 谢谢 如果您希望在所有活动中使用相同内容的相同滑动菜单,那么只需创建一个活动,并对滑动菜单的逻辑进行编码,将其名称命名为BaseActivity,然后在项目的所有其他活动中扩展此BaseActivity,而不是appcompativity,因此,您可以在所有活动中使用它 另一种方
谢谢 如果您希望在所有活动中使用相同内容的相同滑动菜单,那么只需创建一个活动,并对滑动菜单的逻辑进行编码,将其名称命名为
BaseActivity
,然后在项目的所有其他活动中扩展此BaseActivity
,而不是appcompativity
,因此,您可以在所有活动中使用它
另一种方法是@Veeresh的评论中建议的包含滑动菜单的片段,这也是一个很好的选择
回答你的评论,在你的主要活动中做一个变量,如下所示
<?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"
>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
sothree:umanoParallaxOffset="100dp"
sothree:umanoDragView="@+id/dragView"
sothree:umanoOverlay="true"
sothree:umanoScrollableView="@+id/main">
<!-- MAIN CONTENT -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_toolbar"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
sothree:theme="@style/ActionBar"
android:layout_width="match_parent"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_marginTop="?attr/actionBarSize"
/>
</RelativeLayout>
<!-- SLIDING LAYOUT -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:clickable="true"
android:focusable="false"
android:id="@+id/dragView">
<LinearLayout android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal"
android:id="@+id/panel">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="vertical"
android:layout_weight="0.8">
<TextView
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="20sp"
android:gravity="center_vertical"
android:paddingLeft="10dp"/>
<TextView
android:id="@+id/foooter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="16sp"
android:gravity="center_vertical"
android:paddingLeft="10dp"/>
</LinearLayout>
<ImageButton
android:layout_width="68dp"
android:layout_height="68dp"
android:src="@mipmap/playy"
android:id="@+id/play"
android:background="@null"
/>
<ImageButton
android:layout_width="68dp"
android:layout_height="68dp"
android:src="@mipmap/queue"
android:id="@+id/queue"
android:background="@null"
/>
</LinearLayout>
<FrameLayout
android:id="@+id/ss"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
>
<!-- <TextView
android:id="@+id/list_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:gravity="center"
android:text="Main Content"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="true"
android:textSize="16sp" />-->
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="@+id/panel">
<LinearLayout
android:id="@+id/songThumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:gravity="center"
android:layout_weight="0.9"
android:layout_marginTop="?attr/actionBarSize"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/album_art"
android:src="@mipmap/music"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_above="@+id/linearLayout"
android:layout_alignParentStart="true"
>
<SeekBar
android:id="@+id/songProgressBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:layout_marginBottom="20dp"
android:thumb="@mipmap/seek_handler"
android:progressDrawable="@mipmap/img_seekbar_bg"
android:paddingLeft="6dp"
android:paddingRight="6dp"/>
<!-- Timer Display -->
<LinearLayout
android:id="@+id/timerDisplay"
android:layout_above="@id/songProgressBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:layout_marginBottom="10dp">
<!-- Current Duration Label -->
<TextView
android:id="@+id/songCurrentDurationLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:textColor="#eeeeee"
android:textStyle="bold"/>
<!-- Total Duration Label -->
<TextView
android:id="@+id/songTotalDurationLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:textColor="#04cbde"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="200dp"
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="0.1"
android:id="@+id/linearLayout"
>
<!-- Previous Button -->
<ImageButton
android:id="@+id/bt_previous"
android:src="@mipmap/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:layout_weight="2"
/>
<!-- Backward Button -->
<!-- Play Button -->
<ImageButton
android:id="@+id/bt_play"
android:src="@mipmap/playy"
android:layout_width="100px"
android:layout_height="100px"
android:background="@null"
android:layout_weight="2"/>
<!-- Forward Button -->
<!-- Next Button -->
<ImageButton
android:id="@+id/bt_next"
android:src="@mipmap/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:layout_weight="2"
/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</RelativeLayout>
它是类变量,然后在onCreate
方法中
public SlidingUpPanelLayout ss; // this is important step , did you followed this in your mainactivity
然后,在其他活动中,您可以直接通过ss
在单独的布局中创建滑动内容,并在任何活动中对其进行充气
ss=(SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
将滑动面板放在片段中,并在活动中需要时添加片段(),我建议您将整个滑动面板xml放在布局文件中,并在每个活动中调用它。当然,使用片段是困难的,但更方便。我是否需要为所有活动使用相同类型的xml布局,或者仅一个xml布局就足以用于所有活动?不,只有一个布局包含滑动菜单BaseActivityMainActivity扩展AppCompativity,第二个活动扩展了主活动…………这是正确的吗?我已经将我的slidinguppanel定义为SlidingUpPanelLayout ss=(SlidingUpPanelLayout)findViewById(R.id.sliding_布局);在MainActivity中,我是否需要在我的第二个Activity中创建MainActivity的对象来访问SlidengUppanelAccept my answer,然后单击我答案左上角upvote按钮下方的绿色复选框
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
View inflatedLayout = inflater.inflate(R.layout.layout1, null, false);
inflatedLayout.setLayoutParams(lp);