创建一个android工程,我使用的是eclipse,android2.2版本,真机测试。
//layout文件的编写///
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginTop="15dip"
android:text="Ver 1.1" />
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/logo" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="35dip"
android:layout_marginRight="5dip"
android:text="唐浩" />
// 由于涉及到横竖屏的切换,所以背景由代码控制
activity_main.xml/
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout layout=(LinearLayout)findViewById(R.id.layout);
//背景自动适应
Tools.AutoBackground(this, layout, R.drawable.loading, R.drawable.loading);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
/工具类/
public class Tools {
public static void AutoBackground(Activity activity, View view, int Background_v,
int Background_h) {
int orient = ScreenOrient(activity);
if (orient == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { // 纵向
view.setBackgroundResource(Background_v);
} else { // 横向
view.setBackgroundResource(Background_h);
}
}
// 获取屏幕方向
public static int ScreenOrient(Activity activity) {
int orient = activity.getRequestedOrientation();
if (orient != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
&& orient != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
// 宽>高为横屏,反正为竖屏
WindowManager windowManager = activity.getWindowManager();
Display display = windowManager.getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
orient = screenWidth
: ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
return orient;
}
}
// 由于楼主不会PS...大家将就看,是这么个意思,实际开发中UI有人负责的,我们要做的就是弄好排版