Android 學習記錄-UDACITY項目0反饋

UDACITY 剛剛登陸中國,前一個月納米學位免費試用,好奇的我爲了檢測自己的學習成果,從最簡單的組件組合項目做起,沒報多大希望地提交了自己做的東西,沒想到第二天就給我了回覆,效率真是高。。也從反饋中看到了許多缺陷,需要注意的地方。。

效果圖

最終效果

存在的問題

1 . 佈局我採用LinearLayout 典型的線性佈局

回覆建議:

I can’t click on the other buttons when I rotated the device. To fix

that, you can change to a ScrollView or you can also create the

landscape layout.

可以用ScrollView 包裹着 LinearLayout

2 . 字體大小我用的dp,

回覆建議:

When setting text sizes, you should normally use sp, or”scale-independent pixels”. This is like the dp unit, but it is alsoscaled by the user’s font size preference.

It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user’s preference.

sp可以更好的適應屏幕,具體參見stackoverflow單位區別

3 . 我的屬性值都是直接給出

   <Button
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Build It Bigger"
        android:textAllCaps="true"
        android:background="#F08C35"
        android:onClick="click_build"/>
    <Button
        android:layout_width="200dp"
        android:background="#F08C35"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Xyz Reader"
        android:textAllCaps="true"
        android:onClick="click_reader"/>

回覆建議:

It is a good practice to define dimensions value in dimens.xml file, colors value in color.xml file, string in string.xml file …

Try to have this practice for your next project

將一些配置值保存在string,color,dimens 裏面便於修改和維護。

4 . 提示信息

 Toast.makeText(getApplicationContext(),
                "This button will launch my Score app",
                Toast.LENGTH_SHORT).show();

回覆建議:

Please put the text “This button will launch…” into string.xml file and use getString to access this ressource
Besides you can change or translate your text easily later.

提示信息保存到string文件,重用性比較高。

5 . 功能寫成函數

 public void click_library(View view){
        Toast.makeText(getApplicationContext(),
                "This button will launch my Library app",
                Toast.LENGTH_SHORT).show();
    }

回覆建議:

You can create a helper function to avoid repeating Toast.makeText…..:

void DisplayText(String s){
Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show(); }

And call this:

public void clic_score(View view) {
DisplayText(R.string.scores_toast); }

6 . 點擊事件

public void click_build(View view){
        Toast.makeText(getApplicationContext(),
                "This button will launch my Build app",
                Toast.LENGTH_SHORT).show();
    }

    public void click_myOwn(View view){
        Toast.makeText(getApplicationContext(),
                "This button will launch my my own app",
                Toast.LENGTH_SHORT).show();
    }

回覆建議:

Here other lazy way: using butterknife library - http://jakewharton.github.io/butterknife/

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
}

 @OnClick({ R.id.button,
   R.id.button2,
   R.id.button3,
   R.id.button4,
   R.id.button5,
   R.id.button6})

public void showToast(Button button) {
Toast.makeText(this, String.format(getString(R.string.button_message), button.getText()),
Toast.LENGTH_SHORT).show();
}

以上就是存在的問題,雖然應用很簡單,但是問題和需要注意和改進的地方還是有的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章