Android 实现slidingdrawer的另一种方法,该方法自api 17以来已被弃用
在我的应用程序中,我有一个滑动抽屉,里面有图像按钮,单击它会显示图像描述和信息。所以基本上我只使用一个XML文件和一个Java文件来实现这一点。(但我注意到添加更多的图像按钮和法师来显示需要一段时间才能加载)。现在,由于API 17不推荐使用滑动抽屉,我对该应用程序的未来下载有点担心。现在我的问题是,有没有其他方法来实现这一点,而不使用滑动抽屉或旋转器。我真的不想为每个图像创建一个xml和java文件(我最终会得到100多个xml和java文件) 这是我目前拥有的代码 XML: 有谁能帮忙或提出建议吗?我认为这是个不错的选择Android 实现slidingdrawer的另一种方法,该方法自api 17以来已被弃用,android,android-layout,android-intent,Android,Android Layout,Android Intent,在我的应用程序中,我有一个滑动抽屉,里面有图像按钮,单击它会显示图像描述和信息。所以基本上我只使用一个XML文件和一个Java文件来实现这一点。(但我注意到添加更多的图像按钮和法师来显示需要一段时间才能加载)。现在,由于API 17不推荐使用滑动抽屉,我对该应用程序的未来下载有点担心。现在我的问题是,有没有其他方法来实现这一点,而不使用滑动抽屉或旋转器。我真的不想为每个图像创建一个xml和java文件(我最终会得到100多个xml和java文件) 这是我目前拥有的代码 XML: 有谁能帮忙或提出
如果不使用
滑动抽屉
,您可以修改抽屉的方向这是左侧的滑动抽屉
,对吗?如果是这样,你可以调查一下
这是Android支持库的一部分,您应该能够非常简单地用它替换XML,并且向后兼容API4
从那一页,有一个例子
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
我宁愿建议一个简单的滑动菜单,这是我自己创造的 我使用的概念 滑块按钮和内容面板 最初,滑块按钮位于左侧(在我的示例中),当您单击它时,它会移动,并且内容窗格可见 我是如何做到这一点的 我使用左边距播放,因此当您按下滑块按钮时,内容窗格(最初隐藏)将变为屏幕宽度/3,当您再次按下时,内容窗格将隐藏 这是我的密码
public class MainActivity extends Activity {
boolean toggle_open=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void open(View v){
switch (v.getId()) {
case R.id.imageButton1:
if(!toggle_open){
RelativeLayout header=(RelativeLayout)findViewById(R.id.header);
Display size=getWindow().getWindowManager().getDefaultDisplay();
int widthby2=size.getWidth()/3;
RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
lp.setMargins(size.getWidth()/2, 0, 0, 0);
header.setLayoutParams(lp);
RelativeLayout slider=(RelativeLayout)findViewById(R.id.panel);
slider.setLayoutParams(new RelativeLayout.LayoutParams((size.getWidth()/2),size.getHeight()));
slider.setVisibility(View.VISIBLE);
toggle_open=true;
}
else{
RelativeLayout header=(RelativeLayout)findViewById(R.id.header);
RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
lp.setMargins(0, 0, 0, 0);
header.setLayoutParams(lp);
RelativeLayout slider=(RelativeLayout)findViewById(R.id.panel);
slider.setVisibility(View.GONE);
toggle_open=false;
}
break;
default:
break;
}
}
}
//xml代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<RelativeLayout
android:id="@+id/header"
android:background="@android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:padding="20dp" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@android:color/black"
android:onClick="open"
android:src="@android:drawable/ic_dialog_dialer" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageButton1"
android:layout_toRightOf="@+id/imageButton1"
android:text="Admin Panel"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/panel"
android:visibility="gone"
android:layout_toLeftOf="@+id/header"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@android:color/darker_gray"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<fragment class="com.example.avanse.FragmentLayout$TitlesFragment"
android:id="@+id/titles"
android:layout_width="match_parent" android:layout_height="match_parent"/>
</RelativeLayout>
</RelativeLayout>
普通android,您可以使用抽屉布局。
但是我推荐给用户和程序员更好的可用性。应用程序Umano的家伙们提供的SlideingPanel现在似乎是最好的方式。您可以在以下位置找到它: 我在另一个SOF帖子中找到了相关信息: :D 编辑:这个看起来也很有希望:
(在youtube视频中,从右到左和从左到右似乎都能正常工作,但如果你下载实际的演示应用程序,你会发现它也可以从下到上和从上到下)DrawerLayout也可以与旧的Android版本一起工作,就像它在v4支持库中一样。@A.Binzxxxxxx,如何使用DroperLayout从底部拉出菜单?大约60年来没有编写过任何android-抱歉
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- your content surrounded by a layout to signify that it's actually content -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iM1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:adjustViewBounds="true"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
<!-- your sliding menu in its own layout -->
<LinearLayout
android:layout_gravity="start"
android:layout_width="240dp"
android:layout_height="wrap_content">
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/icon_1" />
<RelativeLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/icon_background1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/asample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/imageicon1"/>
.....
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
public class MainActivity extends Activity {
boolean toggle_open=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void open(View v){
switch (v.getId()) {
case R.id.imageButton1:
if(!toggle_open){
RelativeLayout header=(RelativeLayout)findViewById(R.id.header);
Display size=getWindow().getWindowManager().getDefaultDisplay();
int widthby2=size.getWidth()/3;
RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
lp.setMargins(size.getWidth()/2, 0, 0, 0);
header.setLayoutParams(lp);
RelativeLayout slider=(RelativeLayout)findViewById(R.id.panel);
slider.setLayoutParams(new RelativeLayout.LayoutParams((size.getWidth()/2),size.getHeight()));
slider.setVisibility(View.VISIBLE);
toggle_open=true;
}
else{
RelativeLayout header=(RelativeLayout)findViewById(R.id.header);
RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
lp.setMargins(0, 0, 0, 0);
header.setLayoutParams(lp);
RelativeLayout slider=(RelativeLayout)findViewById(R.id.panel);
slider.setVisibility(View.GONE);
toggle_open=false;
}
break;
default:
break;
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<RelativeLayout
android:id="@+id/header"
android:background="@android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:padding="20dp" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@android:color/black"
android:onClick="open"
android:src="@android:drawable/ic_dialog_dialer" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageButton1"
android:layout_toRightOf="@+id/imageButton1"
android:text="Admin Panel"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/panel"
android:visibility="gone"
android:layout_toLeftOf="@+id/header"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@android:color/darker_gray"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<fragment class="com.example.avanse.FragmentLayout$TitlesFragment"
android:id="@+id/titles"
android:layout_width="match_parent" android:layout_height="match_parent"/>
</RelativeLayout>
</RelativeLayout>