仿新浪微博 android,第一期--从零开始仿制新浪微博---android

创建一个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有人负责的,我们要做的就是弄好排版

acb1ecec416da9fd2516ba3d8b550860.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值