调整布局进入其他布局 [英] Resize layout to get into other layout

查看:138
本文介绍了调整布局进入其他布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个menuView.xml布局是在我所有的活动的布局。这种布局对每个边界一列这样一个标题栏:

I created a menuView.xml layout to be in all of the layouts of my activity. This layout has one column on each border and a title bar like this:

我在其他布局这种方式插入此布局:

I insert this layout in the other layouts this way:

<!-- Show menu -->
<com.example.MenuView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

但是,如果布局中的一个具有全屏视图,该视图的一部分得到由MenuView覆盖,所以...

But if one of the layouts has full screen view, part of this view gets covered by the MenuView, so...

怎么能告诉这个观点,它的大小适应空格内MenuView不得到所涵盖?

How could I tell to this view to adapt its size to the blank space inside the MenuView to not get covered by it?

更新 - 完整的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>

这里发生的是,这些2相对布局得到由MenuView(最暗的GRE边界和顶部黑条)覆盖,并且提供了理想的方式是,这些2布局得到拟合到空白空间(最清晰的灰色)

What happens here is that these 2 Relative layouts get covered by the MenuView (The darkest gre borders and the top black bar), and the ideal way would be that these 2 layouts get fitted to the blank space (the clearest gray).

我可以解决这个设置保证金大小的相对布局,以适应它里面,但我知道这是不是做的最好办法,所以我不知道是否有另一种方式。

I can solve this setting margin sizes to the Relative layouts to fit inside of it, but i know this is not the best way to do it, so I don't know if there is another way.

推荐答案

我想为您解决问题的最佳途径是继承。
如果您定义可作为模板的所有活动的充实Activitys自己的内容添加到。
我不知道你自定义的菜单'由'什么,但作为一个简单的例子:

I think the best way to solve your issue is with inheritance. If you define an Activity that can be used as a template for all your fleshed out Activitys to add their content to. I don't know what you custom menu is 'made of' but as a simple example:

与code。创建一个基本的活动:

Create a basic Activity with code:

  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>

然后创建XML为特定的活动,在这种情况下,一个简单的'Hello World'的布局:

Then create your xml for a specific Activity, in this case a simple 'Hello World' layout:

  <?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>

但现在当你写的code对于此活动,延长而非Activity类直接ActivityWithMenu和夸大这个XML布局如下:

But now when you write the code for this Activity, extend 'ActivityWithMenu' instead of the Activity class direct and inflate this xml layout as follows:

  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);
      }
  }

我已经加入了code制作在父类ActivityWithMenu假设你不希望他们都在这里,而不是全屏的活动显示的方式,但你可以将它移动到父类,如果合适的。

I have added the code for making the Activity fullscreen here instead of in the parent ActivityWithMenu class assuming that you wouldn't want them all displayed that way but you could move it into the parent class if appropriate.

希望这有助于。

这篇关于调整布局进入其他布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆