开发者

Screen size problem

In my app which create an calendar using buttons..its working fine in all resolution except device with screen resolution 240X320..Actually it runs but some part is not visible..i have send the code and the screen shot..please anyone help me to resolve this problem..

code for xml...

    <?xml version="1.0" encoding="UTF-8"?>

<RelativeLayou开发者_高级运维t xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
        <LinearLayout android:id="@+id/linearLayout" 
            android:gravity="center_horizontal|center_vertical"
            android:orientation="horizontal"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="20dp"
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent"     
            android:background="#00000000">
            <Button 
            android:id="@+id/pBtnPrevMonth" 
            android:gravity="center_horizontal|center_vertical"
            android:layout_width="53dp" 
            android:layout_height="40dp"
            android:textColor="#000000"
            android:background="@drawable/but_left">
            </Button>
            <TextView 
            android:gravity="center_horizontal|center_vertical"
            android:id="@+id/tTextMonth"        
            android:layout_width="50dp" 
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/pBtnPrevMonth"
            android:textColor="#000000">
            </TextView>
            <TextView 
            android:gravity="center_horizontal|center_vertical"
            android:id="@+id/tTextYear" 
            android:layout_width="50dp" 
            android:layout_marginRight="5dp"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/tTextMonth"
            android:textColor="#000000">
            </TextView> 
            <Button 
            android:id="@+id/pBtnNextMonth" 
            android:gravity="center_horizontal|center_vertical"
            android:layout_width="53dp" 
            android:layout_height="40dp"
            android:layout_toRightOf="@+id/tTextYear"
            android:textColor="#000000"
            android:background="@drawable/but_right">
            </Button>   
    </LinearLayout> 

    <LinearLayout   
            android:id="@+id/liVLayout"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/linearLayout"
            android:layout_marginTop="15dp">            
    </LinearLayout>   

    <LinearLayout android:id="@+id/linearLayout1" 
            android:gravity="center_horizontal|center_vertical"
            android:orientation="vertical"  
            android:layout_marginLeft="7dp"
            android:layout_marginRight="7dp"    
            android:layout_below="@+id/liVLayout"
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent"     
            android:background="#00000000">
            <TextView 
            android:gravity="center_vertical"
            android:text="Hello"
            android:layout_marginTop="5dp"
            android:id="@+id/txtView" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:textColor="#000000">
            </TextView> 
            <TextView 
            android:gravity="center_vertical"
            android:id="@+id/txtNoteView" 
            android:layout_marginTop="5dp"
            android:layout_below="@+id/txtView" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:textColor="#000000">
            </TextView> 
            <TextView 
            android:gravity="center_horizontal|center_vertical"
            android:text="Advertisement"
            android:layout_marginTop="5dp"
            android:id="@+id/txtAdvView" 
            android:layout_below="@+id/txtNoteView" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:textColor="#000000">
            </TextView> 
    </LinearLayout>

</RelativeLayout>

code for java......

public void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.calendar_frm); 

        txtView=(TextView) findViewById(R.id.txtView);

            txtNoteView=(TextView) findViewById(R.id.txtNoteView);

            txtAdvView=(TextView) findViewById(R.id.txtAdvView);
}

public boolean initDay()
{
  LinearLayout layoutVertical = (LinearLayout) findViewById(R.id.liVLayout);
   LinearLayout rowLayout=null;

LayoutParams param = new      LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,1);

//Create Button
for (i = 0; i<6; i++)
{
    rowLayout = new LinearLayout(this);

    rowLayout.setWeightSum(7);

    layoutVertical.addView(rowLayout,param);

    for(j=0;j<7;j++)
    {

           pBtnDay[i][j]=new Button(this);

           rowLayout.addView(pBtnDay[i][j],param); 

           pBtnDay[i][j].setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);

    }
}               
return true;                    

}

snapshot which for device having resolution 240 X 400

Screen size problem

Snapshot for device having resolution 240 X 320 is...

Screen size problem

so by seeing this you know the problem...please suggest me..


create another xml layout file for this resolution with smaller icons or suchlike

"By default, Android resizes your application layout to fit the current device screen. In most cases, this works fine. In other cases, your UI might not look as good and might need adjustments for different screen sizes. For example, on a larger screen, you might want to adjust the position and size of some elements to take advantage of the additional screen space, or on a smaller screen, you might need to adjust sizes so that everything can fit on the screen.

The configuration qualifiers you can use to provide size-specific resources are small, normal, large, and xlarge. For example, layouts for an extra large screen should go in layout-xlarge/. "

http://developer.android.com/guide/practices/screens_support.html#support


Done your project programatically use display metrics to get width and height $DisplayMetrics metrics; metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); screenWidth = metrics.widthPixels; screenHeight = metrics.heightPixels;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜