Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android是否有一些与iPhone相当的struts和Spring?_Android_Iphone_Layout - Fatal编程技术网

Android是否有一些与iPhone相当的struts和Spring?

Android是否有一些与iPhone相当的struts和Spring?,android,iphone,layout,Android,Iphone,Layout,我一直在努力寻找一些类似于iPhone的struts和Spring的Android系统。不要说重力:-) 当然可以说重力,但请解释如何防止视图在线性布局或相对布局中被推离屏幕。或者给我看一些其他的布局,让屏幕在不把东西撞到视线之外的情况下被填满 在iphoneinterfacebuilder中,我只需适当地设置弹簧,使每个视图占用尽可能多的可用空间,但不会占用更多空间。这使得iPhone布局能够很好地处理方向变化 在Android中,我读到的主要方法似乎是创建多个布局文件夹,如layout po

我一直在努力寻找一些类似于iPhone的struts和Spring的Android系统。不要说重力:-)

当然可以说重力,但请解释如何防止视图在线性布局或相对布局中被推离屏幕。或者给我看一些其他的布局,让屏幕在不把东西撞到视线之外的情况下被填满

在iphoneinterfacebuilder中,我只需适当地设置弹簧,使每个视图占用尽可能多的可用空间,但不会占用更多空间。这使得iPhone布局能够很好地处理方向变化

在Android中,我读到的主要方法似乎是创建多个布局文件夹,如layout port和layout land,然后在它们之间复制XML布局文件,但这似乎非常容易出错,而且,我能停止从按下屏幕上的其他按钮获得一个大的自定义视图的唯一方法是为特定的屏幕大小和方向精确地设置其布局高度。考虑到Android显示器的市场范围,这让人感觉越来越痛苦

下面是一个例子:

<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的高度,这样它就可以在不让seekbar看不见的情况下尽可能多地填充屏幕。尝试将Imageview android:layout\u height设置为fill\u parent,以了解我的意思

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


我能想到的唯一解决方案(但还没有真正尝试)是在代码中做一些事情来检测屏幕大小和其他小部件,但我不愿意这样做,因为似乎应该有一个简单的XML布局解决方案。

尝试使用
android:layout\u weight
,同时将
android:layout\u width
android:layou height
设置为
0dp
(取决于父视图的
android:orientation
值)

Android中没有比你想做的更好的等价物了……

我也有类似的问题(老实说,问题更多),所以我开发了SpringLayout:。 如果我理解正确,那么我认为我成功地实现了您想要的(图像占用了尽可能多的空间):



这是你为什么不使用android:layout\u weight

?根据上面的评论,你对“spring”的描述听起来和layout\u weight的用途一模一样。啊哈,非常感谢——layout\u weight似乎做了我想要的事情,虽然我似乎不得不做很多调整才能得到我想要的效果-我会将这些回答标记为正确答案,但它们是评论,嗯。。。
<?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>