0
我在android中创建了一个自定义控件(按钮),它具有左图像和中心文本以及右箭头图像。在使用此自定义控件时,我必须绘制此按钮的上边框和下边框。getLeft()不适用于android中的TextView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical" >
<View
android:id="@+id/viwupperline"
style="@style/bsf_viwline"/>
<RelativeLayout
android:id="@+id/lytcontrollayout"
android:layout_width="fill_parent"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:layout_height="38dip"
android:layout_margin="5dip" >
<ImageView
android:id="@+id/imgrightimage"
android:layout_width="25dip"
android:layout_height="25dip"
android:layout_centerVertical="true"
/>
<TextView
android:id="@+id/txttextoncontrol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/imgrightimage"
android:textSize="17sp"
android:textColor="@color/grey" >
</TextView>
<ImageView
android:id="@+id/imgarrow"
android:layout_width="20dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/bsfarrowright" >
</ImageView>
</RelativeLayout>
<View
android:id="@+id/viwbottomline"
style="@style/bsf_viwline"/>
如果我只用一个按钮,然后全上缘和下缘有显示。否则,下边框应该与TextView一致。我创造了边界的观点。我将getLeft()用于TextView。如果下边框应该最小化,我设置边距左视图如下:
public void AddMarginToLowerBorder()
{
int margin = _text.getLeft();
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)_viewlower.getLayoutParams();
params.setMargins(margin, 0, 0, 0);
_viewlower.setLayoutParams(params);
}
但getLeft()不起作用。
如果我这样设置,
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)_viewlower.getLayoutParams();
params.setMargins(70, 0, 0, 0);
_viewlower.setLayoutParams(params);
,那么它工作正常。
请帮我解决这个问题。