質問

I have following XML code:

<ScrollView>
    <TextView />
    <TextView />
    <TextView />
    <Button />
</ScrollView>

Is it possible to give all the children of my ScrollView automatically the attribute "android:minHeight=XY"? The best solution would be an attribute for ScrollView but I think I have to write some java code for that, haven't I?

役に立ちましたか?

解決

You'll need android:layout_width and android:layout_height in any case for all your Views. Only way you can avoid this, would be by defining a style and apply that style to all your TextViews and Button.

他のヒント

Is it possible to ... automatically

To do some thing automatically you need to code it ;)

Actually android gives you two choices here, you can create your own ScrollView and use it in the layout like this:

<com.my.package.MyScrollView>
    <TextView />
    <TextView />
    <TextView />
    <Button />
</com.my.package.MyScrollView>

Or you can use Android Styles, to set a variable for your width, and it will be used in all the ScrollView.

Personally I recommend using the second method it sounds more native to Android.

Try this:

<ScrollView minHeight="android:minHeight=XY">
    <TextView />
    <TextView />
    <TextView />
    <Button />
</ScrollView>

The code processing the XML should look for minHeight and apply it to the children appropriatly.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top