ฉัน deveoping Android v2.2 แอพ
ฉันมีส่วน
ในการonCreateView(...)เรียกกลับของคลาสแฟรกเมนต์ของฉันฉันขยายเลย์เอาต์ไปที่แฟรกเมนต์ตามด้านล่าง:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.login, null);
return view;
}
ไฟล์โครงร่างที่พองเกินด้านบนคือ (login.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Username" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Username" />
</LinearLayout>
ฉันต้องการตั้งค่าองค์ประกอบpaddingTopข้างต้น<LinearLayout>และฉันต้องการที่จะทำในรหัสJavaแทนทำใน xml
วิธีการตั้งค่าpaddingTopการ<LinearLayout>ในส่วนรหัสชั้นเรียนของฉัน Java ??
viewเป็น LinearLayout อยู่แล้วไม่จำเป็นต้องค้นหาอีกครั้งในกรณีนี้ รับนี้เป็นคนพิเศษแม้ว่า
findViewByIdแล้วโทรหาsetPaddingมัน