相关疑难解决方法(0)

以编程方式在视图上添加填充

我正在开发Android v2.2应用程序.

我有一个片段.

onCreateView(...)我的片段类的回调中,我将布局扩展到片段,如下所示:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.login, null);

    return view;
}
Run Code Online (Sandbox Code Playgroud)

上面膨胀的布局文件是(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>
Run Code Online (Sandbox Code Playgroud)

我想设置一个paddingTop上面的<LinearLayout>元素,我想在Java代码中执行它而不是在xml中执行它.

如何设置paddingTop<LinearLayout>我的片段Java类代码?

android padding android-widget android-emulator android-layout

221
推荐指数
9
解决办法
23万
查看次数