如何在活动的特定位置打开列表视图?

3
我希望能够从屏幕底部打开列表视图,到接近中间高度。我不知道如何做到这一点。我只知道它只能通过片段来完成,并且我不知道如何在我的当前活动和XML中使用它。我想要的效果如下图所示: enter image description here 我希望我的问题很清楚。我知道如何实现列表视图,但我不知道如何按照我想要的方式实现它(我的意思是出现和消失时不会干扰其他视图)。这个列表应该覆盖其他视图。
编辑: 包括我的XML文件,以便您可以查看我在设计方面做了什么。
 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
   >


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
   >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="content_desc_overlay"
        android:src="@drawable/ic_launcher"
        android:id="@+id/img_view"

        />


    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/iv_overlay"
        android:src="@drawable/doom"
        android:scaleType="matrix"

        />

</FrameLayout>


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Open List"
        android:id="@+id/btn_screenshot"
        android:layout_gravity="right|top"
        />

</RelativeLayout>

有什么建议吗?如果有源代码会更好。谢谢。


这是基于XML设计的。因此,您需要向我们展示您的XML文件。 - Amsheer
请等一下,我会包含这个,但这很简单。 - stacy queen
@Amsheer,已完成,请现在查看。 - stacy queen
2个回答

1
将您的列表视图放在一个单独的空白活动中,并在清单中将活动主题设置为对话框。
<activity
        android:name=".ui.activities.EditSignatureActivity"
        android:label="@string/title_activity_edit_signature"
        android:theme="@android:style/Theme.Holo.Light.Dialog" >
    </activity>

当点击打开列表按钮时,启动新的意图:

public void openListButton_OnClick(View v) {
    Intent intent = new Intent(HomeActivity.this, List.class);
    startActivity(intent);
}

不要忘记调整新的listView活动的大小,以适应您需要的位置,并添加边距。

你是指ListView的背景吗?如果是的话,你可以将背景设置为类似这个颜色 android:background="#88c2c4c9" ,其中第一个88是透明度,后面的部分是颜色值,你可以根据自己的需要进行更改。 - Hawraa Khalil
它给我以下错误。 java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或其后代)。 - stacy queen
是的,在后台活动中更改您的应用程序主题样式为您可以在res->values->styles下找到它。 - Hawraa Khalil
你在新的Activity中是否使用了extends Activity而不是ActionBarActivity? - Hawraa Khalil
是的,那是我的错误。 - stacy queen
显示剩余5条评论

0

我会给你一个样例,但你需要进行修改。如果有任何疑问,请随时询问。

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:layout_marginTop="50dp"
        android:id="@+id/top_row">

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="horizontal" >

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Text A" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="horizontal" >

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Text B" />
        </LinearLayout>
    </LinearLayout>

    <ListView 
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/top_row"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="15dp"></ListView>

</RelativeLayout>

注意:您需要加载数据到listView中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接