def onCreate(self): sentence_lines = iter(sentence_text.splitlines()) all_sentence_pairs = list(zip(sentence_lines, sentence_lines)) self.sentence_pairs = [] while len(self.sentence_pairs) < 10 and all_sentence_pairs: # noinspection PyUnresolvedReferences i = self.random.nextInt(len(all_sentence_pairs)) sentence_pair = all_sentence_pairs.pop(i) if len(sentence_pair[0]) <= 9: self.sentence_pairs.append(sentence_pair) self.players = [ Player(self._activity, is_inverted, self.on_solved) for is_inverted in (True, False) ] self.player_progress = {player: 0 for player in self.players} vlayout = LinearLayout(self._activity) vlayout.setOrientation(LinearLayout.VERTICAL) for i, player in enumerate(self.players): if i: self.winner_label = TextView(self._activity) self.winner_label.setTextSize(50) # noinspection PyUnresolvedReferences self.winner_label.setLayoutParams( LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1)) vlayout.addView(self.winner_label) player.opponent = self.players[(i + 1) % 2] player.on_create(vlayout) self.set_sentence(player) self._activity.setContentView(vlayout)
def on_create(self, parent_layout): vlayout = LinearLayout(self.activity) vlayout.setOrientation(LinearLayout.VERTICAL) vlayout.setGravity(Gravity.BOTTOM) if self.is_inverted: vlayout.setRotation(180) parent_layout.addView(vlayout) self.top_layout = LinearLayout(self.activity) self.top_layout.setOrientation(LinearLayout.HORIZONTAL) self.top_label = TextView(self.activity) # noinspection PyUnresolvedReferences self.top_label.setLayoutParams( LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1)) self.top_label.setTextSize(50) self.top_layout.addView(self.top_label) self.next_button = Button(self.activity) # noinspection PyUnresolvedReferences self.next_button.setLayoutParams( LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 0)) self.next_button.setText('Hint') self.next_button.setOnClickListener(ButtonClick(self.next)) self.top_layout.addView(self.next_button) vlayout.addView(self.top_layout) self.solution_layout = LinearLayout(self.activity) self.solution_layout.setOrientation(LinearLayout.HORIZONTAL) self.solution_layout.setGravity(Gravity.LEFT) self.solution_label = TextView(self.activity) self.solution_label.setText('') self.solution_label.setTextSize(50) self.solution_layout.addView(self.solution_label) vlayout.addView(self.solution_layout) self.shelf_layout = LinearLayout(self.activity) self.shelf_layout.setOrientation(LinearLayout.HORIZONTAL) self.shelf_layout.setGravity(Gravity.CENTER) vlayout.addView(self.shelf_layout)
def rowLayout(self): return LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
def __init__(self, context): RelativeLayout.__init__(self, context) # This getColor call deprecated in API level 23. self.lightBackground = context.getResources().getColor( android.R.color.background_light) self.darkText = 0xff000000 # Header header = LinearLayout(context) header.setOrientation(LinearLayout.VERTICAL) header.setId(1) self.placeLabel = TextView(context) self.placeLabel.setTextSize(self.placeLabel.getTextSize() * 1.5) self.placeLabel.setGravity(Gravity.CENTER) headerLine = View(context) headerLine.setBackgroundColor(self.lightBackground) headerLineParams = LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 1) # 1 pixel in height header.addView(self.placeLabel) header.addView(headerLine, headerLineParams) # Middle - containing the forecast layout self.scrollView = ScrollView(context) self.scrollView.setId(2) # Footer footer = LinearLayout(context) footer.setOrientation(LinearLayout.VERTICAL) footer.setId(3) footerLine = View(context) footerLine.setBackgroundColor(self.lightBackground) footerLineParams = LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 1) # 1 pixel in height self.creditLabel = TextView(context) footer.addView(footerLine, footerLineParams) footer.addView(self.creditLabel) # The forecast layout self.forecastLayout = LinearLayout(context) self.forecastLayout.setOrientation(LinearLayout.VERTICAL) self.scrollView.addView(self.forecastLayout) # Layout parameters headerParams = RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) headerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP) headerParams.addRule(RelativeLayout.CENTER_HORIZONTAL) scrollParams = RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) scrollParams.addRule(RelativeLayout.CENTER_HORIZONTAL) scrollParams.addRule(RelativeLayout.BELOW, 1) scrollParams.addRule(RelativeLayout.ABOVE, 3) footerParams = RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) footerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM) self.addView(header, headerParams) self.addView(self.scrollView, scrollParams) self.addView(footer, footerParams)
def onCreate(self, savedInstanceState: android.os.Bundle) -> void: super().onCreate(savedInstanceState) r = self.getResources() # #******************************************************** layout = LinearLayout(self) layout.setLayoutParams( LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)) layout.setPadding( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, r.getDisplayMetrics()), TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, r.getDisplayMetrics()), TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, r.getDisplayMetrics()), TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, r.getDisplayMetrics())) layout.setOrientation(LinearLayout.VERTICAL) to_field = EditText(self) to_field.setLayoutParams( LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)) to_field.setHint("To") subject_field = EditText(self) subject_field.setLayoutParams( LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)) subject_field.setHint("Subject") message_field = EditText(self) message_field.setLayoutParams( LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0)) message_field.setGravity(Gravity.TOP) message_field.setHint("Message") send_button = Button(self) lp = LinearLayout.LayoutParams( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, r.getDisplayMetrics()), LinearLayout.LayoutParams.WRAP_CONTENT) lp.gravity = Gravity.RIGHT send_button.setLayoutParams(lp) send_button.setHint("Send") send_button.setOnClickListener(OnClickListener(message_field)) layout.addView(to_field) layout.addView(subject_field) layout.addView(message_field) layout.addView(send_button) self.setContentView(layout)