ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Android响应式布局

2019-09-29 02:26:16  阅读:244  来源: 互联网

标签:android android-layout android-tablelayout android-resolution


我正在构建应用程序(计算器).我使用带有按钮的表格布局.它在三星Galaxy II的屏幕上看起来很完美,但在大屏幕上看起来非常糟糕.按钮高度很小.如何在更大的屏幕上拉伸按钮?

布局XML如下:

<ScrollView xmlns:android="http://schemas.an
    xmlns:tools="http://schemas.android.com/
    android:layout_width="match_parent"     
    android:layout_height="match_parent"    
    android:gravity="right"                 
    android:paddingBottom="@dimen/activity_v
    android:paddingLeft="@dimen/activity_hor
    android:paddingRight="@dimen/activity_ho
    android:paddingTop="@dimen/activity_vert
    tools:context=".MainActivity" >         


<TableLayout                                
    android:layout_width="match_parent"     
    android:layout_height="match_parent"    
    android:gravity="right"                 
    >                                       



    <TableRow                               
        android:id="@+id/tableRow1"         
        android:layout_width="match_parent" 
        android:layout_height="0dp">        

        <Button                             
            android:id="@+id/Button01"      
            android:layout_width="0dp"      
            android:layout_weight="0.33"    
            android:layout_height="fill_pare
            android:text="@string/button_1" 
            android:visibility="visible" /> 

        <Button                             
            android:id="@+id/Button02"      
            android:layout_width="0dp"      
            android:layout_weight="0.34"    
            android:layout_height="fill_pare
            android:text="@string/button_2" 

        <Button                             
            android:id="@+id/Button03"      
            android:layout_width="0dp"      
            android:layout_weight="0.33"    
            android:layout_height="fill_pare
            android:text="@string/button_3" 

    </TableRow>                             

    <TableRow                               
        android:id="@+id/tableRow2"         
        android:layout_width="match_parent" 
        android:layout_height="0dp" >       

    <Button                                 
        android:id="@+id/Button04"          
        android:layout_width="0dp"          
            android:layout_weight="0.33"    
        android:layout_height="fill_parent" 
        android:text="@string/button_4" />  

    <Button                                 
        android:id="@+id/Button05"          
        android:layout_width="0dp"          
        android:layout_weight="0.34"        
        android:layout_height="fill_parent" 
        android:text="@string/button_5" />  

    <Button                                 
        android:id="@+id/Button06"          
        android:layout_width="0dp"          
        android:layout_weight="0.33"        
        android:layout_height="fill_parent" 
        android:text="@string/button_6" />  

     </TableRow>                            

    <TableRow                               
        android:id="@+id/tableRow3"         
        android:layout_width="match_parent" 
        android:layout_height="0dp" >       

        <Button                             
            android:id="@+id/Button07"      
            android:layout_width="0dp"      
            android:layout_weight="0.33"    
            android:layout_height="fill_pare
            android:text="@string/button_7" 

        <Button                             
            android:id="@+id/Button08"      
            android:layout_width="0dp"      
            android:layout_weight="0.34"    
            android:layout_height="fill_pare
            android:text="@string/button_8" 

        <Button                             
            android:id="@+id/Button09"      
            android:layout_width="0dp"      
            android:layout_weight="0.33"    
            android:layout_height="fill_pare
            android:text="@string/button_9" 

    </TableRow>                             

    <TableRow                               
        android:id="@+id/tableRow4"         
        android:layout_width="match_parent" 
        android:layout_height="0dp" >       

        <Button                             
            android:id="@+id/ButtonUndo"    
            android:layout_width="0dp"      
            android:layout_weight="0.33"    
            android:layout_height="fill_pare
            android:text="@string/button_und

        <Button                             
            android:id="@+id/Button00"      
            android:layout_width="0dp"      
            android:layout_weight="0.34"    
            android:layout_height="fill_pare
            android:text="@string/button_0" 

        <Button                             
            android:id="@+id/ButtonCheck"   
            android:layout_width="0dp"      
            android:layout_weight="0.33"    
            android:layout_height="fill_pare
            android:text="@string/button_che

    </TableRow>                             

    <TableRow                               
        android:id="@+id/ResTable"          
        android:layout_width="match_parent" 
        android:layout_height="0dp" >       

        <TableLayout                        
            android:layout_weight="0.3"     
            android:id="@+id/table_score_cor

            <TableRow                           
                android:id="@+id/tableRow5_11"  
                android:layout_width="wrap_conte
                android:layout_height="fill_pare
                android:gravity="center_vertical
                    <TextView                     
                    android:id="@+id/labelCorrec
                    android:layout_width="wrap_c
                    android:layout_height="fill_
                    android:ems="4"             
                    android:text="@string/correc
                    android:gravity="center_vertic
                    android:textSize="15sp" />    
                </TableRow>                   

            <TableRow                           
                android:id="@+id/tableRow5_12"  
                android:layout_width="wrap_conte
                android:layout_height="0dp" >   

                <TextView                     
                    android:id="@+id/scoreCorr
                    android:layout_width="0dp"
                    android:layout_height="fil
                    android:ems="4"           
                    android:gravity="center_ve
                    android:text=""           
                    android:textSize="30sp"   
                    android:textStyle="bold" /
            </TableRow>                     
        </TableLayout>                      

        <ImageView                            
            android:id="@+id/imageView1"      
            android:layout_width="wrap_content
            android:layout_height="fill_parent
            android:layout_weight="0.3"       
            android:contentDescription="@strin
            android:fitsSystemWindows="true"  
            android:scaleType="fitCenter"     
            android:src="@drawable/trees" />  

        <TableLayout                        
            android:id="@+id/table_score_inc
            android:layout_weight="0.3">      

            <TableRow                       
                android:id="@+id/tableRow5_21"  
                android:layout_width="wrap_conte
                android:layout_height="fill_pare
                android:gravity="center_vertical
                <TextView                     
                    android:id="@+id/labelIncorrec
                    android:layout_width="wrap_con
                    android:layout_height="fill_pa
                    android:ems="4"             
                    android:text="@string/incorrec
                    android:gravity="center_vertic
                    android:textSize="15sp" />    
            </TableRow>                       
            <TableRow                           
                android:id="@+id/tableRow5_22"  
                android:layout_width="wrap_conte
                android:layout_height="fill_pare

                <TextView                     
                    android:id="@+id/scoreInco
                    android:layout_width="0dp"
                    android:layout_height="fil
                    android:ems="4"           
                    android:gravity="center_ve
                    android:text=""           
                    android:textSize="30sp"   
                    android:textStyle="bold" /
            </TableRow>                       
        </TableLayout>                        

        </TableRow>                           

        <TableRow                             
            android:id="@+id/tableRow_menu"   
            android:layout_width="wrap_content
            android:layout_height="fill_parent
            <Button                             
                android:id="@+id/ButtonPlus"    
                android:layout_width="0dp"    
                android:layout_height="38dp"
                android:layout_weight="0.25"  
                android:text="@string/action_p
            <Button                             
                android:id="@+id/ButtonMinus"   
                android:layout_width="0dp"    
                android:layout_height="38dp"
                android:layout_weight="0.25"  
                android:text="@string/action_m
            <Button                             
                android:id="@+id/ButtonMult"    
                android:layout_width="0dp"    
                android:layout_height="38dp"
                android:layout_weight="0.25"  
                android:text="@string/action_m
                        <Button                     
                android:id="@+id/ButtonDivide"  
                android:layout_width="0dp"    
                android:layout_height="38dp"
                android:layout_weight="0.25"  
                android:text="@string/action_d
            </TableRow>                         

            </TableLayout>                      

</ScrollView>                               

解决方法:

总而言之,您需要创建不同的布局/绘图以支持所有屏幕.这取决于您的要求,例如,如果您想要在小屏幕中包含2个按钮,在大屏幕上包含4个按钮,那么显然您必须创建不同的布局.

如果你想在所有屏幕上显示相同数量的按钮,那么我建议你准备不同的图像/绘图集并将它们包含在你的项目中.除了将图像放在特定的可绘制文件夹中之外,您无需执行任何操作.

还有一件事,如果它是一个简单的背景,那么你可以创建9补丁图像,以便它可以伸展你想要的任何尺寸或你的设备支持.

更多研究:

> http://developer.android.com/guide/practices/screens_support.html
> Supporting Different Screen Sizes
> Supporting Different Densities
> Implementing Adaptative UI Flows

标签:android,android-layout,android-tablelayout,android-resolution
来源: https://codeday.me/bug/20190929/1830200.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有