我有一个RelativeLayout
activity.xml的代码
<RelativeLayout
android:layout_height="50dip"
android:layout_width="fill_parent"
android:id="@+id/relativeLayout"
android:background="#686868"
>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_margin="5dip"
android:layout_alignParentLeft="true"
android:text="Back"
android:textColor="#FFFFFF"
android:id="@+id/btnBack"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/title_header"
android:text="Header of page"
android:layout_centerInParent="true"
android:textColor="#FFFFFF"
/>
</RelativeLayout>
这是活动的代码:-
public class MainActivity extends Activity {
int valCheck;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
if(valCheck==0)
{
//here set title again for backbutton is "backPreviousPage" and set
//position again of title_header is right of backButton with
//margin=5dip(not set position is centerInParent as code
}
}
}
我不知道通过代码在 relativeLayout 中获取元素和设置边距的方法..你能帮我吗?