首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >创建Android布局以支持4英寸和5英寸屏幕尺寸问题

创建Android布局以支持4英寸和5英寸屏幕尺寸问题
EN

Stack Overflow用户
提问于 2014-03-20 18:01:29
回答 2查看 5.8K关注 0票数 3

我已经参考了更多的文档,也遇到了this和许多帖子,这似乎是我的问题。但我想在这里得到更具体的建议或答案。

问题是,我已经为5英寸手机(如nexus4)开发了我的主屏幕,所以它在上面看起来相当不错。当我在4英寸手机(如nexus )上运行相同的应用程序时,主屏幕看起来不像在5英寸手机上。这太奇怪了,有些按钮,视图都不合适。我现在该怎么做?我还尝试创建一个单独的布局文件夹,比如layout-320dp和layout-normal。两个屏幕都在HDPI部分下,所以我不能创建单独的布局文件夹。此外,我在我的主屏幕上使用了更多的图像视图,并给出了更具体的填充purpose.If的数值。我减少了可绘制文件夹中的图像大小,这意味着我可以在4英寸的屏幕上获得漂亮的UI。

My_home_screen_layout:

代码语言:javascript
代码运行次数:0
运行
复制
<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" xmlns:tools="http://schemas.android.com/tools">

<fragment
    android:id="@+id/fragment_actionbar"
    android:layout_width="fill_parent"
    android:layout_height="44dp"
    android:layout_alignParentTop="true"
    android:name=".ActionbarFragment" >   

<RelativeLayout
    android:id="@+id/fragment_content"
    android:layout_below="@id/fragment_actionbar"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">


<ImageView
        android:id = "@+id/sty"
    android:layout_width="match_parent"
        android:layout_height="fill_parent"           
        android:scaleType="fitXY"
        android:background="@drawable/_splash_blank_screen"
        />   

  <TextView
        android:id="@+id/textLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"                  
        android:singleLine="false"          
        android:layout_toRightOf="@+id/girl_home"               
        android:textSize="14sp"
        android:layout_marginTop="12dp"
        android:layout_marginLeft="5dp"
        android:textColor="#675836"
        android:textStyle="bold" />     


   <TextView
        android:id="@+id/textLabel_weather"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"                  
        android:singleLine="false"   
        android:layout_below="@+id/textLabel"  
        android:layout_marginLeft="5dp"  
        android:layout_marginTop="5dp"   
        android:layout_toRightOf="@+id/girl_home"               
        android:textSize="14sp"            
        android:textColor="#675836"
        android:textStyle="bold" />   


    <TextView
          android:id="@+id/text_calendar"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignRight="@+id/reference_calendar_button_icon_home"
          android:paddingTop="90dp"
          android:paddingRight="1dip"
          android:singleLine="true"             
          android:textColor="@color/text_highlight"
          android:textSize="12sp"
          android:textStyle="bold" />



 <ImageView
        android:id="@+id/girl_home"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"            
        android:paddingTop="10dp" 
        android:layout_marginLeft="1dp" 
        android:paddingLeft="1dp"   
        android:src="@drawable/ic_mix_match_toast"     
        android:singleLine="true"  
         />     


 <ImageView
        android:id="@+id/today_outfit"
        android:layout_width="220dp"
        android:layout_height="320dp"                    
        android:layout_below="@+id/girl_home"  
        android:layout_marginTop="15dp"                          
        android:layout_gravity="center_horizontal"
        android:singleLine="true"  
         />


 <ImageView
        android:id="@+id/reference_calendar_button_icon_home"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"  
        android:paddingTop="20dp"
        android:paddingLeft="55dp"              
        android:layout_toRightOf="@+id/today_outfit"              
        android:singleLine="true"                
        android:src="@drawable/btn_calendar_home" /> 

  <ImageView
        android:id="@+id/closet_button_icon_home"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"  
        android:paddingTop="30dp"
        android:paddingLeft="40dp"  
        android:layout_below="@id/text_calendar"        
        android:layout_toRightOf="@+id/today_outfit"      
        android:src="@drawable/ic_closet_home_new" /> 


      <ImageView
        android:id="@+id/search_notes"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"        
        android:paddingTop="150dp"
        android:paddingLeft="80dp"    
        android:src="@drawable/btn_search_home"            
        android:layout_gravity="center_horizontal" /> 

      <TextView
        android:id="@+id/text_weather"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"                     
        android:singleLine="false"            
        android:layout_below="@+id/chat_button_icon_home" 
        android:layout_marginTop="-5dp"
        android:paddingLeft="50dip"          
        android:textSize="12dip"
        android:text="TODAY'S FORECAST"
        android:textColor="@color/text_highlight"
        android:textStyle="bold" />


      <TextView
        android:id="@+id/today_look"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"                     
        android:singleLine="false"            
        android:layout_below="@+id/today_outfit" 
        android:paddingLeft="65dip"  
        android:paddingTop="1dip"        
        android:textSize="12sp"        
        android:textColor="@color/text_highlight"
        android:textStyle="bold" />

       <TextView
        android:id="@+id/textLabel_weather_location"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_below="@+id/today_look"
        android:layout_marginTop="38dp"   
        android:layout_marginLeft="10dp"                  
        android:singleLine="false"           
        android:layout_toRightOf="@+id/chat_button_icon_home"                 
        android:textSize="14dip"
        android:textColor="#675836"
        android:textStyle="bold" /> 


      <TextView
          android:id="@+id/text_window"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"                
          android:layout_below="@+id/window_button_icon_home"                        
          android:singleLine="true"
          android:paddingLeft="260dp"              
          android:textColor="@color/text_highlight"
          android:textSize="12sp"
          android:textStyle="bold" />

      <ImageView
          android:id="@+id/chat_button_icon_home"
          android:layout_width="70dp"
          android:layout_height="70dp"
          android:layout_below="@+id/today_look" 
          android:layout_marginTop="35dp"  
          android:layout_marginLeft="10dp"             
          android:singleLine="true"
           />

      <ImageView
          android:id="@+id/window_button_icon_home"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"              
          android:layout_toRightOf="@+id/today_outfit"   
          android:layout_below="@+id/text_inspire"  
          android:layout_marginTop="20dp"      
          android:paddingLeft="30dp"              
          android:singleLine="true"
          android:src="@drawable/btn_window_shop_new" />

      <ImageView
          android:id="@+id/inspire_idea"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"                       
          android:paddingLeft="30dp"
          android:paddingTop="25dp"
          android:singleLine="true"
          android:layout_below="@+id/text_closet"
          android:layout_toRightOf="@+id/today_outfit" 
          android:src="@drawable/btn_inspire_home" />

      <TextView
          android:id="@+id/text_closet"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/closet_button_icon_home"              
          android:paddingTop="1dip"
          android:paddingLeft="275dp"
          android:singleLine="true"             
          android:textColor="@color/text_highlight"
          android:textSize="12sp"
          android:textStyle="bold" />

      <TextView
          android:id="@+id/text_inspire"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/today_outfit"
          android:paddingLeft="270dp"
          android:paddingTop="-10dp"
          android:singleLine="true"             
          android:textColor="@color/text_highlight"
          android:textSize="12sp"
          android:textStyle="bold" />        
</RelativeLayout>

任何帮助都将不胜感激。提前谢谢。

EN

回答 2

Stack Overflow用户

发布于 2014-03-20 18:20:27

您可以根据heightwidth创建布局文件夹。例如- layout-w360dp, layout-w480dp or layout-h480dp or layout-h600dp。然后根据您的要求在这些布局中设置视图。

编辑-

对于Nexus-4创建layout-w720dp,对于Nexus-SNexus-One创建layout-w480dp。这现在起作用了。

票数 1
EN

Stack Overflow用户

发布于 2014-03-20 18:40:40

我会推荐你使用线性布局作为父布局,使用权重作为权重,在equal parts.no中划分屏幕,需要创建任何额外的布局文件夹。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22529375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档