我正在开发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类代码??

我正在使用一个web视图,其中我正在添加一个图像视图。如何将此图像视图的背景设置为透明?

我试过了:

mImageview.setBackgroundResource(R.color.trans);

其中trans→<color name="trans">#00000000 </color>。

我不明白如何使用这个属性。谁能多告诉我一点吗?

我如何设置一个ImageView的宽度和高度编程?