मैं एंड्रॉइड 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>तत्व को सेट करना चाहूंगा , और मैं इसे xml में करने के बजाय जावा कोड में करना चाहता हूं ।
कैसे स्थापित करने के लिए paddingTopकरने के लिए <LinearLayout>मेरी टुकड़ा जावा वर्ग कोड में ??
viewपहले से ही LinearLayout है, इस मामले में इसे फिर से खोजने की कोई आवश्यकता नहीं है। हालांकि यह एक विशेष है।
findViewByIdऔर फिर उसsetPaddingपर कॉल कर सकें।