프로그래밍 방식으로 일부 버튼을 추가하려고합니다. 그러나 어떤 이유로 긴 텍스트는 내 직선형 레이아웃에서 전체 버튼을 누르게됩니다.긴 텍스트는 선형 레이아웃에서 버튼을 내림
버튼 :
public class MyButton : Button
{
public MyButton(Context ctx) : base(ctx)
{
SetTextColor(Color.White);
SetTextSize(Android.Util.ComplexUnitType.Dip, 20);
var llp = new LinearLayout.LayoutParams(0, 100, 1);
llp.SetMargins(4, 0, 4, 4);
LayoutParameters = llp;
SetBackgroundColor(Color.Black);
}
}
행 (I는 버튼의 두 행이)
public class MyRow : LinearLayout
{
public MyRow(Context context) : base(context)
{
if (LayoutParameters == null)
LayoutParameters = GenerateDefaultLayoutParams();
LayoutParameters.Height = ViewGroup.LayoutParams.WrapContent;
LayoutParameters.Width = ViewGroup.LayoutParams.MatchParent;
((LinearLayout.LayoutParams)LayoutParameters).Gravity = GravityFlags.Top;
((LinearLayout.LayoutParams)LayoutParameters).Weight = 0;
Orientation = Orientation.Horizontal;
}
}
헤더 :
public class MyHeader : LinearLayout
{
public MyHeader(Context context, IAttributeSet set) : base(context, set)
{
Orientation = Orientation.Vertical;
LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent, 0);
}
protected override void OnAttachedToWindow()
{
base.OnAttachedToWindow();
Draw();
}
private void Draw()
{
for (int r = 0; r < 2; r++)
{
var row = new MyRow(Context);
for (int i = 0; i < 4; i++)
{
var btn = new MyButton(Context);
if (r == 0 && i == 0)
btn.Text = "long text long text long text ";
else
btn.Text = $"Btn {r}.{i}";
row.AddView(btn);
}
AddView(row);
}
}
}
그리고 I는 XAML에서 헤더를 추가 이렇게 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<App1.Resources.layout.MyHeader
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/myHeader1" />
</LinearLayout>
나는 버튼의 내용이 단추의 위치를 움직여서는 안된다는 것을 알 수 있습니다. 하지만 그렇습니다. 어떤 아이디어? 귀하의 버튼에
추가하려고했습니다. Ellipsize = Android.Text.TextUtils.TruncateAt.Marquee; 단추에 대해서는 이지만 불행히도 여전히 동일한 동작입니다. – Evelie