0

Ich habe dies: enter image description hereFabrikat Kind von Scroll 1/3 Größe

mein Problem ist, dass ich ein Linearlayout Wrapper mit einem Scrollview und ein Linearlayout innen .. Ich mag, dass jeder Punkt 1/3 der sein scrollviews höhe egal wie viele einzelteile ich hineinlege.

Wenn ich Elemente zum Linearlayout hinzufüge ist es linearlayouts, wenn ich 3 'Items' hinzufüge ist es fast in Ordnung .. aber wenn ich 8 Items hinzufüge, sind sie alle ziemlich klein und scrollbar. Das ist, was ich will, aber ich möchte, dass sie die Höhe von 1/3 des scrollview/linearlayout haben.

Ich möchte es so ausrichten, dass es so groß ist wie die Tasten im 2. Layout, das ich habe.

Ich kann es einfach nicht richtig machen, hoffe, es ist nur eine einfache Lösung, die ich nicht gesehen habe.

mein Code so weit:

<LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="0dip" 
       android:orientation="vertical" 
       android:layout_weight="75"> 
       <ScrollView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:id="@+id/scrollView2" 
        android:layout_gravity="center_horizontal" 
        android:fillViewport="true" 
        android:scrollbarSize="5dp" 
        android:fadeScrollbars="false" 
        android:layout_marginRight="5dp" 
        android:layout_marginLeft="5dp" 
        android:scrollbarThumbVertical="@drawable/custom_scroll_style"> 
        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:id="@+id/coats" 
         android:orientation="vertical" 
         android:weightSum="75"> 

       </LinearLayout> 
       </ScrollView> 
      </LinearLayout> 

Das ist meine Art 'Kinder' an das Layout von der Scroll

seine wirklich eingewickelt der Zugabe bekommen
LinearLayout w0 = new LinearLayout(this); 
     LinearLayout w1 = new LinearLayout(this); 
     ImageView w2 = new ImageView(this); 
     TextView w3 = new TextView(this); 
     TextView w4 = new TextView(this); 

     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 25); 
     params.setMargins(pixelToDp(0),pixelToDp(5),pixelToDp(0),pixelToDp(5)); 
     w0.setLayoutParams(params); 
     w0.setOrientation(LinearLayout.HORIZONTAL); 
     w0.setClickable(true); 

     w0.setBackgroundColor(Color.argb(100, 100, 100, 100)); 
     w0.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       for (int i = 0; i < LLCoats.getChildCount(); i++) { 
        View vv = LLCoats.getChildAt(i); 
        vv.setSelected(false); 
        vv.setBackgroundColor(Color.argb(100, 100, 100, 100)); 
       } 
       LinearLayout LL = (LinearLayout)LLCoats.getChildAt(i); 
       TextView TV = (TextView)LL.getChildAt(1); 
       TV.requestFocus(); 

       if(TV.getError() != null) 
       { 
        Snackbar snackbar = Snackbar 
          .make(findViewById(android.R.id.content), ""+TV.getError(), Snackbar.LENGTH_LONG); 
        snackbar.show(); 
       } 



       v.setSelected(true); 
       v.setBackgroundColor(Color.argb(255,255,255,255)); 
      } 
     }); 

     LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 2); 
     w1.setLayoutParams(params2); 
     w1.setOrientation(LinearLayout.VERTICAL); 
     w1.setClickable(false); 

     LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT,1); 
     w2.setLayoutParams(params3); 
     w2.setScaleType(ImageView.ScaleType.FIT_CENTER);  

     LinearLayout.LayoutParams params4 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT,1); 
     w3.setLayoutParams(params4); 
     w3.setTextSize(25f); 
     w3.setGravity(Gravity.CENTER); 
     w3.setClickable(false); 

     LinearLayout.LayoutParams params5 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT,1); 
     w4.setLayoutParams(params5); 
     w4.setTextSize(45f); 
     w4.setGravity(Gravity.CENTER); 
     w4.setClickable(false); 

     w1.addView(w2); 
     w1.addView(w3); 

     w0.addView(w1); 
     w0.addView(w4); 

     LLCoats.addView(w0); 

UPDATE !:

Jetzt komisch, da ich einen Weg gefunden habe, die Höhe zu berechnen und hinzuzufügen:

DisplayMetrics display = this.getResources().getDisplayMetrics(); 

     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, pixelToDp((int)(display.heightPixels* .8 * 0.25))); 

Das funktioniert wirklich gut auf meinem PI64 und einem ASUS-Tablet, aber mein Handy macht die Höhe 100% der gleichen wie der Scrollview, wie passiert ??

Antwort

0

Ich machte es, wie das funktioniert, um die Bildschirmgröße bekommen * 0,8, weil der Bildschirm als Popup verwendet wird und dann 0,25 als Elemente sind 1/4 des Bildschirms, und am Ende -10 für meine Margen

DisplayMetrics display = this.getResources().getDisplayMetrics();   

     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int)(display.heightPixels* .8 * 0.25 - pixelToDp(10)));  

     params.setMargins(pixelToDp(0),pixelToDp(5),pixelToDp(0),pixelToDp(5)); 
Verwandte Themen