私はカスタムボタン(Label + Image)でScrollViewを作成したいと思っていますが、Buttonオブジェクトの適切な位置付けLabelとImageに問題があります。ScrollViewとCustomButton
コード:
class TestScreen(Screen):
def change(self, btn, pos):
print pos
def populate(self):
scroll = self.ids.myscroll
grid = self.ids.scrollgrid
btn = Button(size_hint_y=None, width='29sp', text='')
box = BoxLayout(size=btn.size, pos=btn.pos,orientation='horizontal')
image = Image(source='image.png', size_hint_x=None, width=74)
label = Label(size_hint_x=None, width=100, text='test')
box.add_widget(image)
box.add_widget(label)
btn.add_widget(box)
grid.add_widget(btn)
btn.bind(pos=partial(self.change))
と.kvファイル:
<TestScreen>:
Button:
text: 'populate'
size_hint: None, None
size: 100,100
pos: 0,0
on_press: root.populate()
ScrollView:
id: myscroll
size_hint: None, None
size: 300, 500
pos: 100, 100
scroll_x: 0.5
GridLayout:
spacing: 20
padding: 20
id: scrollgrid
size_hint: None, None
cols: 1
size_hint_y: None
children
height: self.minimum_height
width: self.parent.width
最大の問題は、その移入にBoxLayoutを作成する時に()で、btn.posである[0,0]とレンダリング後btn.posが適切な座標に変更されました(posに対してbind()を使ってチェックしました)。上記のBoxLayoutを作成するときに、どのようにして正しいcooridnateを得ることができますか?