我曾与TextView的LinearLayout中的孩子。在在的LinearLayout触摸事件,我从一个值到另一个值变化的LinearLayout布局。但问题是,扩大的LinearLayout孩子,但仍然相同。
Xamarin.Android项目
私人的LinearLayout线性的;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
linear = (LinearLayout)FindViewById(Resource.Id.parentView);
linear.Touch += Linear_Touch;
}
private void Linear_Touch(object sender, View.TouchEventArgs e)
{
{
linear.Layout(0, 0, (500), (500));
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/parentView"
android:background="@android:color/holo_orange_light">
<TextView android:layout_width="50dp"
android:layout_height="50dp"
android:text="Ashok kumar"
android:textSize="13dp"
android:background="@android:color/holo_green_light"/>
</LinearLayout>
预期的结果:TextView中也改变对应的LinearLayout变化
首先,我修改有关重置的LinearLayout布局代码,那么你可以使用Layout_weight让你的目标。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:id="@+id/parentlayout"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_orange_dark">
<TextView
android:layout_width="50dp"
android:layout_height="20dp"
android:layout_weight="1"
android:id="@+id/textView1"
android:text="Ashok kumar"
android:textSize="13dp"
android:background="@android:color/holo_green_light"/>
</LinearLayout>
private void Linear_Touch(object sender, Android.Views.View.TouchEventArgs e)
{
FrameLayout.LayoutParams _params = new FrameLayout.LayoutParams(500, 500);
linear.LayoutParameters = _params;
linear.RequestLayout();
}