小编Aft*_*ain的帖子

使用SlidingUpPanel库在底部保持视图

我在我的一个应用程序中使用该SlidingUpPanelMedia Player.

在幻灯片中,我有媒体控件,我想在顶部显示曲目的艺术作品.我遇到的问题是我希望媒体控件始终保持在屏幕的底部(即使用户拖动面板,这意味着我必须使用该onPanelSlide ()方法).也许像一个视差效果(不确定这是否是正确的名称).这就是我现在所拥有的:

折叠/展开/拖动:
在此输入图像描述 在此输入图像描述 在此输入图像描述

正如您所看到的,当我拖动面板时,控件会粘在顶部.我希望它坚持在屏幕的底部,并在其上方显示艺术品.

我在考虑CoordinatorLayout,但我不知道它是如何工作的!

我的代码:

activity.xml

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.sothree.slidinguppanel.SlidingUpPanelLayout
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        sothree:umanoPanelHeight="92dp"
        sothree:umanoShadowHeight="4dp">

        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <include layout="@layout/details_slide_bar" />
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

details_slide_bar.xml

<LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_gravity="bottom"
              android:orientation="vertical">

    <ImageView
        android:id="@+id/ivArtworkBar"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:visibility="gone"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="92dp"
        android:orientation="horizontal"
        android:id="@+id/lDetailsBar">

        /!-- Content of the detalBar !-->
    </RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

现在,我只是检查面板的状态并相应地调整图稿visibility.

主要活动(MyListActivity.java)

必须有另一种方式!

java android android-layout

11
推荐指数
2
解决办法
1952
查看次数

在嵌套片段之间传递数据

我正在开发一个项目,我必须在片段之间传递数据.所有数据都是从我的DatabaseHandler class(SQLiteOpenHelper)提供的.我正在手写这篇文章,所以忽略语法错误,如果有的话.

这是我的Activity样子(包含SelectionFragment和InfoFragment):

  • 选择片段(包含一个GridView)
  • 信息片段(ViewPager5-6 child fragments)
    • childFragment1
    • childFragment2
    • childFragment3
    • ...

这是我到目前为止所做的:

SelectFrag扩展片段:

MyCommunicator communicator;
GridView myGrid;

onItemSelected(... int position, ...) {
    communicator.respond("The id i get from getTag()..");
}
public void setCommunicator(MyCommunicator communicator) {
    this.communicator = communicator;
}

public interface MyCommunicator {
    public void respond(String id);
}
Run Code Online (Sandbox Code Playgroud)



Activity扩展FragmentActivity实现SelectFrag.MyCommunicator:

FragmentManager manager;
SelectFrag selectFrag;
InfoFrag infoFrag;

onCreate() {
    manager = getSupportFragmentManager();
    selectFrag = (SelectFrag) manager.findFragmentById(...);
    selectFrag.setCommunicator(this);
}

@Override
public void respond(String id) …
Run Code Online (Sandbox Code Playgroud)

android android-fragments

3
推荐指数
1
解决办法
3371
查看次数

在 Java 中用数据替换变量

我得到一个字符串,例如:“用户 << a1 >> 是 << a2 >> 50 岁。”
我还有一个数组,其中包含需要放入字符串中的数据!对于前。a[0]=“约翰”;a[1]= "30"
因此,对于这个例子,我想<< a1 >>John和替换<< a2 >>为 30。

我唯一能找到的是以下问题:How to Replace a set of tokens in a Java String? ,但说实话我什么都不懂,也不确定这是否是我真正想要的。

那么,这真的是我需要处理的吗?如果是的话我就去读一些教程。
提前致谢。

编辑:注意:我无法控制传入的字符串。所以这将与我输入的方式完全相同。所有变量都是表格<< a0 >>,变量的数量未知(甚至可能有 10 个变量)。

java

0
推荐指数
1
解决办法
794
查看次数

标签 统计

android ×2

java ×2

android-fragments ×1

android-layout ×1