2011-03-08 37 views
5

我一直在努力寻找一些与iPhone的struts和spring相同的东西。并且不要说重力:-)Android有一些相当于iPhone的支杆和弹簧吗?

不要说引力,但然后解释如何我可以防止意见被推离屏幕LinearLayout或RelativeLayout。或者向我展示一些其他布局,使屏幕可以填充而不会让事物看不见。

在iPhone界面生成器中,我只是适当地设置弹簧,让每个视图占用尽可能多的空间,但没有更多。这使iPhone布局能够很好地处理方向变化。

在Android中,我阅读的主要方法似乎是创建多个布局文件夹,如布局端口和布局布局,然后复制XML布局文件,但似乎高度容易出错,并且仍然是我唯一的方法可以停止从屏幕上按下其他按钮来获得较大的自定义视图,即为特定的屏幕大小和方向精确地设置其layout_height。鉴于安卓显示器在市场上的广泛应用,这种感觉会越来越令人痛苦。

下面是一个例子:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="@string/hello" /> 
    <ImageView android:id="@+id/imageView1" android:src="@drawable/icon" 
     android:layout_height="320dip" android:layout_width="fill_parent"></ImageView> 
    <SeekBar android:layout_height="wrap_content" android:id="@+id/seekBar1" 
     android:layout_width="fill_parent"></SeekBar> 
</LinearLayout> 

这些都只是默认小部件。我藐视你找到一些其他方法来设置ImageView高度,以便它尽可能多地填充屏幕而不会将搜索栏撞到视线之外。试着将Imageview android:layout_height设置为fill_parent来查看我的意思。

我已经尝试过相对布局和表格布局以及各种技巧。也许我缺少一些简单的东西,但如果我能找到它,我会被诅咒的......

我能想到的唯一解决方案(但还没有真正尝试)是在代码中执行某些操作来检测屏幕大小和其他小部件,但我不喜欢走这条路线,因为它似乎应该有一个简单的XML布局解决方案。使用android:layout_weight在设置android:layout_widthandroid:layout_height0dp

+3

你为什么不使用'Android版本: layout_weight'? – user634618 2011-03-08 13:13:42

+0

根据上面的评论,你对'spring'的描述听起来和layout_weight是完全一样的。 – 2011-03-08 13:23:54

+0

啊哈,非常感谢 - layout_weight看起来像我想要的东西,尽管我似乎不得不调整它以获得我想要的效果 - 我将这些响应标记为正确答案,但它们是评论,嗯... – 2011-03-08 13:49:07

回答

1

尝试(取决于父视图的android:orientation值)。

没有比这更好相当于Android的你想要做什么......

0

我有类似的问题(更多人是诚实的),所以我开发SpringLayout中:https://github.com/sulewicz/springlayout。 如果我理解正确的话,那么我想我设法达到你想要的东西(图像需要尽可能多的空间可能):

<?xml version="1.0" encoding="utf-8"?> 
<org.coderoller.springlayout.SpringLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white" > 

    <TextView 
     android:id="@+id/A" 
     android:layout_width="match_parent" 
     android:layout_height="32dp" 
     app:layout_alignParentTop="true" 
     android:text="Test" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_below="@id/A" 
     app:layout_above="@+id/seekBar1" 
     android:src="@drawable/ic_launcher" /> 

    <SeekBar 
     android:id="@id/seekBar1" 
     android:layout_width="match_parent" 
     android:layout_height="32dp" 
     app:layout_alignParentBottom="true" /> 

</org.coderoller.springlayout.SpringLayout> 

这里是screenshot