【问题标题】:How to change dynamically layout of child of LinearLayout on zooming如何在缩放时动态更改 LinearLayout 子级的布局
【发布时间】:2019-02-12 14:22:33
【问题描述】:

我有以 TextView 作为子项的 LinearLayout。在 LinearLayout 上的触摸事件中,我将 LinearLayout 的布局从一个值更改为另一个值。但问题是 LinearLayout 放大了,但 child 保持不变。

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 也随着线性布局的变化而变化

【问题讨论】:

  • 文本视图的大小固定为50dp,所以不能再大了...
  • 如果我捏缩放布局,它不会改变吗?

标签: android xamarin xamarin.android


【解决方案1】:

首先,我修改了你关于重置 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();

    }

【讨论】:

    猜你喜欢
    • 2013-10-17
    • 1970-01-01
    • 2012-12-24
    • 1970-01-01
    • 2014-08-17
    • 2012-04-18
    • 1970-01-01
    • 2017-01-10
    • 2021-12-31
    相关资源
    最近更新 更多