2

カスタム レイアウトを含むレイアウトがあります。ある要素から別の要素にスタイルを渡したいと思います。レイアウトを膨らませるクラスがあり、必要に応じて投稿できます。このデザイン要素は、必要に応じてサイズが異なる 2 つの異なるレイアウトによって追加されます。

Child layout

<TableLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal">
    <TableRow android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_width="fill_parent" android:id="@+id/tableRow1">
        <Button android:text="1" android:id="@+id/nb1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="40sp" android:layout_margin="1dip" android:minWidth="70dip"></Button>
        <Button android:text="2" android:id="@+id/nb2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="40sp" android:layout_margin="1dip" android:minWidth="70dip"></Button>
        <Button android:text="3" android:id="@+id/nb3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="40sp" android:layout_margin="1dip" android:minWidth="70dip"></Button>
    </TableRow>
</TableLayout>

そして、これが親レイアウトです

Parent Layout

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <pearsonartphoto.AJEG.number_viewer android:id="@+id/numberviewer" style="@style/bigViewer" android:layout_alignParentRight="true" android:layout_alignParentBottom="true">
    </pearsonartphoto.AJEG.number_viewer>
</RelativeLayout>

私がやりたいのは、スタイルを渡し、そのスタイルをすべての子、または少なくとも textView 要素で繰り返すことです。これを実現するにはどうすればよいですか?

4

1 に答える 1

3

私の知る限り、Androidには、子のビューをネストするだけでなく、親のスタイルを子のビューに継承する方法はありません。

親にスタイルを適用してstyleAと言い、子要素にスタイルを適用するよりもstyleBと言うことができます。

継承はスタイルで行うことができます。つまり、styleBはstyleAからプロパティを継承し、親の値の一部をオーバーライドすることもできます。

fill_parent wrap_content#00FF00モノスペース

fill_parent wrap_content#00FF00モノスペース

悪いニュースは、すべての子要素にスタイルを設定する必要があるということです:-(

これがいくつかの要素にスタイルを与える唯一の方法だと思います。テーマを定義してアクティビティまたはアプリケーションに適用する必要があるよりも要素のグループにスタイルを与えたい場合、これは通常コードで行われますが、プログラム的にもプロで行う必要があります。

于 2011-09-09T15:37:58.443 に答える