我创建了一个menuView.xml布局,以便在我的活动的所有布局中。此布局在每个边框上都有一列,标题栏如下:
ComposeView http://img845.imageshack.us/img845/2121/d6zp.png
我以这种方式在其他布局中插入此布局:
<!-- Show menu -->
<com.example.MenuView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
但如果其中一个布局具有全屏视图,则此视图的一部分将被MenuView覆盖,因此...
我如何告诉此视图使其大小适应MenuView内的空白区域而不被其覆盖?
更新 - 包含完整的XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@drawable/degradado">
<!-- Show menu -->
<com.example.MenuView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="@+id/Left_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" >
//Here go buttons, views, etc...
</RelativeLayout>
<RelativeLayout
android:id="@+id/Right_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" >
//Here go buttons, views, etc...
</RelativeLayout>
这里发生的是这两个相对布局被MenuView(最黑暗的边框和顶部黑条)覆盖,理想的方式是这两个布局适合空白区域(最清晰的灰色)
我可以将此设置边距大小解决为相对布局以适应其内部,但我知道这不是最好的方法,所以我不知道是否有其他方法。
答案 0 :(得分:0)
我认为解决问题的最佳方法是继承。 如果您定义了一个活动,该活动可以用作所有充实活动的模板,以便将其内容添加到。 我不知道你的自定义菜单是由'制成',但作为一个简单的例子:
使用代码创建基本活动:
public class ActivityWithMenu extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_with_menu_layout);
}
}
和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=".ActivityWithMenu" >
<TextView
android:layout_width="match_parent"
android:layout_height="20dip"
android:background="#ff000000"
android:textColor="#ffffffff"
android:text="Main Menu Title Bar"
android:id="@+id/mainmenutitle" />
<LinearLayout
android:layout_width="20dip"
android:layout_height="match_parent"
android:layout_below="@+id/mainmenutitle"
android:layout_alignParentLeft="true"
android:background="#ff999999"
android:orientation="vertical"
android:id="@+id/lefthandmenu" />
<LinearLayout
android:layout_width="20dip"
android:layout_height="match_parent"
android:layout_below="@+id/mainmenutitle"
android:layout_alignParentRight="true"
android:background="#ff999999"
android:orientation="vertical"
android:id="@+id/righthandmenu" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@+id/righthandmenu"
android:layout_toRightOf="@+id/lefthandmenu"
android:layout_below="@+id/mainmenutitle"
android:orientation="vertical"
android:id="@+id/activitycontent"
/>
</RelativeLayout>
然后为特定的Activity创建xml,在本例中为简单的“Hello World”布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff00ff00"
android:text="Hello World!"
/>
</LinearLayout>
</ScrollView>
但是现在当您编写此Activity的代码时,请直接扩展'ActivityWithMenu'而不是Activity类,并按如下方式扩充此xml布局:
public class Activity1 extends ActivityWithMenu
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
LinearLayout ll = (LinearLayout)findViewById(R.id.activitycontent);
ScrollView sv = (ScrollView)this.getLayoutInflater().inflate(R.layout.activity1_layout, ll, false);
ll.addView(sv);
}
}
我已经在此处添加了使Activity全屏显示的代码,而不是在父ActivityWithMenu类中,假设您不希望它们全部以这种方式显示,但如果合适,您可以将其移动到父类中。
希望这有帮助。