2013-05-13 45 views
2

我有这样的代码:使得TEXTSIZE适应的EditText

<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> 

outcome of code above

我怎样才能让TEXTSIZE调整到EditText上的高度?

我的意思是大写字母跨越编辑文本(这可能是因为LinearLayout中的不同大小)

提前感谢的整体高度。

回答

0

您需要检查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; 
} 
0

我觉得你的问题是这样的。

<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> 

+0

但我想让他们 “权重”。跨越整个空间..在你的例子中,我确实需要设置textSize,它不会调整到屏幕上。 – 2013-05-14 18:57:16