2017-06-28 2 views
-2

Ich möchte 0 bis 9 Tasten in zwei Reihen.Jede Taste haben Overlay eines anderen kleinen Knopfes in der rechten unteren Ecke.Wenn ich auf die Schaltfläche klicken, wird auf Overlay button.sorry Zähler angezeigt werden für mein schlechtes Englisch Vielen dank im VorausWie kann ich eine Taste über eine andere Taste

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 
    <LinearLayout 
    android:id="@+id/expandable2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#000000" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

      <Button 
       android:id="@+id/btn0" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="0" /> 

      <Button 
       android:layout_width="25dp" 
       android:layout_height="25dp" 
       android:layout_alignBottom="@id/btn0" 
       android:layout_alignRight="@id/btn0" 
       android:background="#FFFFFF" 
       android:text="0" /> 
     </RelativeLayout> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="1" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="2" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="3" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="4" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="5" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="6" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="7" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="8" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="9" /> 
    </LinearLayout> 
    </LinearLayout> 
    </LinearLayout> 

Mein Ausgang https://program.dotfit.com/startprogram.aspx

andere Vorschlag geschätzt wird

+0

Sie können framelayout verwenden enthält zwei Tasten und verwenden Sie Gitter-Layout für alle Tasten, keine Notwendigkeit, Layout für alle –

+0

A Button in einem Button ... Was ein ** schrecklich UI ** Sie entwerfen werden. –

+0

yeah bro, es ist eine schreckliche UI ..... ich bin neu in Android wo über UI Design vollständig lernen können –

Antwort

0

Probieren sie es wie diese

01 Einstellung
android:layout_marginLeft="-20dp" 
android:layout_marginTop="10dp" 
0

ein framelayout

<FrameLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true"> 

     <Button 
      android:id="@+id/icon_image" 
      android:layout_width="100dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:background="@color/black" 
      android:text="0" /> 

     <Button     
      android:layout_width="20dp" 
      android:layout_height="20dp" 
      android:layout_gravity="bottom|right" 
      android:background="@color/white" 
      android:layout_marginLeft="6dp" 
      android:src="@drawable/ic_goal_check" /> 
    </FrameLayout> 

Something like this

Danach Verwenden Sie das Layout für alle Tasten wiederverwenden können. Wiederzuverwenden dies in Ihrem xml, erstellen Sie eine benutzerdefinierte Ansicht wie folgt:

public class YourButton extends FrameLayout { 

    private Button buttonOne, buttonTwo; 

    public YourButton(Context context) { 
     super(context); 
     this.context = context; 
     initializeViews(); 
    } 

    public YourButton(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     this.context = context; 
     TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.GoalButton); 
     typedArray.recycle(); 
     initializeViews(); 
    } 

    private void initializeViews() { 
     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     inflater.inflate(R.layout.your_button_layout, this); 
    } 

    @Override 
    protected void onFinishInflate() { 
     super.onFinishInflate(); 
     buttonOne = (TextView) this.findViewById(R.id.button_one); 
     buttonTwo = (ImageView) this.findViewById(R.id.button_two); 
    } 

    public void setCount(String count){ 
     buttonTwo.setText(count); 
    } 
} 

jetzt Sie in Ihrem Layout als

<yourPackageName.YourButton 
     android:id="@+id/button_one" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

Das Haupt Layout einfach und ordentlich halten können.

+0

danke Kumpel ..... was ist mit Hauptlayout? –

+0

Sie können horizontal lineares Layout verwenden, wie Sie jetzt verwenden – amarok

0

Verwenden Sie eine Textansicht, um die Anzahl anzuzeigen, da eine Schaltfläche über einer Schaltfläche bedeutungslos ist. Wie auch immer es zu zeigen.

<RelativeLayout 
android:layout_width = "match_parent" 
android:layout_height = "60dp"> 

<Button 
android:layout_width = "match_parent" 
android:layout_height="match_parent" 
android:id="@+id/btn"/> 
<Button 
android:layout_width = "wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/countbtn" 
android:layout_alignParentBottom="true" 
android:layout_alignParentRight= "true"/> 

</RelativeLayout> 

Verwenden Sie diese Ansicht in Ihrem Grid oder RecyclerView Adapter, um es 10-mal, wie Sie zeigen wollen.

Wenn Sie TextView verwenden möchten, um Count anzuzeigen, entfernen Sie die countBtn und machen Sie es zu einem textView mit den letzten beiden Attributen.

+0

ändern Sie die Breite und Höhe entsprechend ich hielt es 'match_parent' und' 60dp' resp. – Ashwani

Verwandte Themen