【问题标题】:Making the textSize adjust to the EditText使 textSize 调整为 EditText
【发布时间】:2013-05-13 22:14:15
【问题描述】:

我有这个代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:hint="@string/tip_value" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:hint="@string/tip_value" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:hint="@string/tip_value" />

</LinearLayout>

如何使 textSize 适应 EditText 的高度?

我的意思是大写字母跨越编辑文本的整个高度(由于线性布局,大小可能不同)

提前致谢。

【问题讨论】:

    标签: android layout text android-linearlayout


    【解决方案1】:

    您需要检查listView 中每个视图的高度,并为该特定视图定义文本大小。为此,您必须使用自定义适配器在listView 中显示arrayarrayList(或cursor...)。在getView() 下的自定义适配器中,您可以执行convertView.getHeight() 以获取特定视图的精确高度(以像素为单位),然后在getView() 中设置该视图的textView 大小。应该与此类似: (我没有检查这个代码,我正在为你编写它作为示例)

    public View getView(int position, View convertView, ViewGroup parent) {
        .
        .
        .
        View line = convertView;
        float size = line.getHeight();
        TextView text = findViewById...
        text.setTextSize(size-20);
        return line;
    }
    

    【讨论】:

      【解决方案2】:

      我认为你的问题是这样的。

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" >
      
      <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" >
      
          <EditText
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:hint="please Enter" />
      </LinearLayout>
      
      <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" >
      
          <EditText
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:hint="please Enter" />
      </LinearLayout>
      
      <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" >
      
          <EditText
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:hint="please Enter" />
      </LinearLayout>
      

      【讨论】:

      • 但我想让它们“变重”。跨越整个空间..在你的例子中,我确实需要设置 textSize ,它不会适应屏幕。
      猜你喜欢
      • 1970-01-01
      • 2020-06-05
      • 2011-07-30
      • 1970-01-01
      • 2018-07-17
      • 1970-01-01
      • 2021-09-19
      • 2013-02-28
      • 2012-03-09
      相关资源
      最近更新 更多