Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.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
Java 多屏幕支持_Java_Android - Fatal编程技术网

Java 多屏幕支持

Java 多屏幕支持,java,android,Java,Android,我对多屏幕支持有一些问题,我使用dp(dpi)来指定布局高度和布局宽度,我希望这是支持多屏幕的更好方法,但当我尝试使用两部智能手机时,我遇到了两个不同的结果 我举一个例子,这是我使用的布局: <?xml version="1.0" encoding="UTF-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/citie

我对多屏幕支持有一些问题,我使用dp(dpi)来指定布局高度和布局宽度,我希望这是支持多屏幕的更好方法,但当我尝试使用两部智能手机时,我遇到了两个不同的结果

我举一个例子,这是我使用的布局:

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/cities_main_layout"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">

       <ListView
          android:id="@+id/citieslist"
          android:layout_width="wrap_content" 
          android:layout_height="320dip"
          android:layout_gravity="center_vertical"
          android:layout_below="@id/cities_main_layout"
       />

       <LinearLayout 
          android:id="@+id/cities_button_layout"
          android:orientation="horizontal"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/citieslist"
          android:layout_gravity="center_vertical">   
        <Button 
           android:id="@+id/bycountry"
           android:layout_height="50dip"
           android:layout_width="105dip"
           android:background="@drawable/buttonmarket"
           android:text="@string/button_bycountry"
          />
        <Button 
           android:id="@+id/top10"
           android:layout_height="50dip"
           android:layout_width="105dip"
           android:background="@drawable/buttonmarket"
           android:text="@string/button_top10"
          />
        <Button 
           android:id="@+id/recommended"
           android:layout_height="50dip"
           android:layout_width="105dip"
           android:background="@drawable/buttonmarket"
           android:text="@string/button_recommended"
          />

       </LinearLayout>

    </RelativeLayout>

按钮位于布局的底部,我看到两种不同的结果:

在最后一部智能手机中,我可以看到按钮,而在第一部智能手机中,我看不到……怎么了

我必须为任何一组屏幕写一个布局

您的ListView具有

android:layout_height="320dip"
现在,如果手机屏幕变小,它将不适合

尝试这样做:(由于注释而编辑。这在eclipse中正确显示)


我想他应该把它修好

干杯

您的列表视图

android:layout_height="320dip"
现在,如果手机屏幕变小,它将不适合

尝试这样做:(由于注释而编辑。这在eclipse中正确显示)


我想他应该把它修好


干杯

我想说,这是因为您专门为您的
列表视图
声明了一个高度,然后将按钮固定在底部的
线性布局
。尝试将其更改为类似的内容,而不是位于
列表视图的底部

<LinearLayout 
          android:id="@+id/cities_button_layout"
          android:orientation="horizontal"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:alignparentbottom="true"
          android:layout_gravity="center_vertical">   


我不完全确定
align\u parent\u bottom
是否是100%正确的拼写。

我想说,这是因为您专门为
列表视图声明了一个高度,然后将按钮固定在底部的
线性布局
。尝试将其更改为类似的内容,而不是位于
列表视图的底部

<LinearLayout 
          android:id="@+id/cities_button_layout"
          android:orientation="horizontal"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:alignparentbottom="true"
          android:layout_gravity="center_vertical">   


我不完全确定
align\u parent\u bottom
的拼写是否100%正确。

正如其他人所指出的,您的问题是您硬连接了
列表视图的大小。如果您想要一个业务规则“底部有按钮,其余部分由
列表视图填充”,那么实际上您需要编写实现“底部有按钮,其余部分由
列表视图填充”的代码

这里有两种主要方法:

  • 线性布局
    父级用于按钮和
    列表视图
    。使用 android:layout\u height=“0px”
  • 列表视图
    。对按钮使用常规的
    android:layou height
    (可能是在它们自己的
    LinearLayout
    中)和
    android:layou-weight

  • 对按钮和列表视图使用
    RelativeLayout
    父级。 将按钮定义为具有
    android:layout\u alignParentBottom=“true”
    。 将
    列表视图定义为具有
    ndroid:layout\u alignParentTop=“true”
    android:layout_over=“…”
    ,其中
    是按钮
    线性布局的ID


  • 正如其他人所指出的,您的问题是您硬连线了
    列表视图的大小。如果您想要一个业务规则“底部有按钮,其余部分由
    列表视图填充”,那么实际上您需要编写实现“底部有按钮,其余部分由
    列表视图填充”的代码

    这里有两种主要方法:

  • 线性布局
    父级用于按钮和
    列表视图
    。使用 android:layout\u height=“0px”
  • 列表视图
    。对按钮使用常规的
    android:layou height
    (可能是在它们自己的
    LinearLayout
    中)和
    android:layou-weight

  • 对按钮和列表视图使用
    RelativeLayout
    父级。 将按钮定义为具有
    android:layout\u alignParentBottom=“true”
    。 将
    列表视图定义为具有
    ndroid:layout\u alignParentTop=“true”
    android:layout_over=“…”
    ,其中
    是按钮
    线性布局的ID


  • 嗯,我打字的时候,其他人已经打败了我,哈哈,但是是的,你硬连接了很多不应该的东西,包括ListView和按钮。看看这个:

    <?xml version="1.0" encoding="UTF-8"?>
    <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/cities_main_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >      
        <LinearLayout 
            android:id="@+id/cities_button_layout"
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            >   
            <Button 
                android:id="@+id/bycountry"
                android:layout_height="50dip"
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/buttonmarket"
                android:text="@string/button_bycountry"
                />
            <Button 
                android:id="@+id/top10"
                android:layout_height="50dip"
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/buttonmarket"
                android:text="@string/button_top10"
                />
            <Button 
                android:id="@+id/recommended"
                android:layout_height="50dip"
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/buttonmarket"
                android:text="@string/button_recommended"
                />
        </LinearLayout>
    
        <ListView
            android:id="@+id/citieslist"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:layout_above="@id/cities_button_layout"
            />           
    </RelativeLayout>
    
    
    
  • 您的RelativeLayout上有
    android:orientation
    ,它实际上不是RelativeLayout包含的属性

  • 您应该使用按钮的
    布局\权重属性,而不是硬接线尺寸。在我的示例中,所有按钮的宽度均为
    fill\u parent
    ,权重均为1。这使它们均匀地分布空间

  • 首先列出固定按钮布局,将其设置为
    alignParentBottom=“true”
    。然后将ListView设置为填充父项,并在按钮布局上方设置
    layout\u。这将使按钮布局保持在底部,并使ListView占据按钮上方的所有空间

  • 塔达


  • 嗯,我打字的时候,其他人已经打败了我,哈哈,但是是的,你硬连接了很多不应该的东西,包括ListView和按钮。看看这个:

    <?xml version="1.0" encoding="UTF-8"?>
    <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/cities_main_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >      
        <LinearLayout 
            android:id="@+id/cities_button_layout"
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            >   
            <Button 
                android:id="@+id/bycountry"
                android:layout_height="50dip"
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/buttonmarket"
                android:text="@string/button_bycountry"
                />
            <Button 
                android:id="@+id/top10"
                android:layout_height="50dip"
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/buttonmarket"
                android:text="@string/button_top10"
                />
            <Button 
                android:id="@+id/recommended"
                android:layout_height="50dip"
                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/buttonmarket"
                android:text="@string/button_recommended"
                />
        </LinearLayout>
    
        <ListView
            android:id="@+id/citieslist"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:layout_above="@id/cities_button_layout"
            />           
    </RelativeLayout>
    
    
    
  • 您的RelativeLayout上有
    android:orientation
    ,它实际上不是RelativeLayout包含的属性

  • 您应该使用按钮的
    布局\权重属性,而不是硬接线尺寸。在我的示例中,所有按钮的宽度均为
    fill\u parent
    ,权重均为1。这使它们均匀地分布空间

  • <