当我们在android中显示AlertDialog时,它显示在屏幕的中心.有没有办法改变立场?
我有一个隐藏在视图中的布局.在按钮上单击,我希望它从底部向上滑动,向上推动整个屏幕内容,非常类似于whatsapp在聊天屏幕中显示表情符号面板的方式.
我见过SlidingDrawer,这对我不起作用.它需要一个图像作为一个手柄,显示在屏幕的中心,我不希望这样.它还会滑动现有的屏幕内容,我正在寻找一种向上移动现有内容的方法.
更新1:
我尝试使用Sanket Kachhela建议的动画.但隐藏的布局从未显示过.这是代码.
布局(activity_main.xml):
<RelativeLayout
android:id="@+id/main_screen"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:layout_alignParentTop="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:layout_centerInParent="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Slide up / down"
android:layout_alignParentBottom="true"
android:onClick="slideUpDown"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/hidden_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/main_screen">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
活动(MainActivity.java):
package com.example.slideuplayout;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
public class MainActivity extends Activity {
private ViewGroup hiddenPanel;
private boolean isPanelShown;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
hiddenPanel …
Run Code Online (Sandbox Code Playgroud) 我试图让a的背景DialogFragment
完全清楚.
通过将样式项设置android:windowIsFloating
为true(默认值),可以DialogFragment
显示我想要的样式,但背景非常暗淡.
通过设置android:windowIsFloating
为false,我得到了我想要的清晰背景,但DialogFragment可以吹到屏幕的大约95%,只留下一个小小的间隙,你可以看到它覆盖的视图.
我已经尝试了大量的调整,似乎无法覆盖这种行为.
我是否需要使用a PopupWindow
来实现所需的效果,或者是否有一些我可以覆盖的样式项?
如何像chrome浏览器一样拆分菜单,如图所示:
这是我的实际代码
<menu 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"
tools:context="materialtest.vivz.slidenerd.activities.MainActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>
Run Code Online (Sandbox Code Playgroud)