Witam Mam główny ekran.Dodaj układ z parametrami programowo Android
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="55dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_toLeftOf="@+id/toggleButton1"
android:background="@android:drawable/btn_default"
android:contentDescription="@string/app_name"
android:scaleType="centerCrop"
android:src="@drawable/plus_grey" />
<LinearLayout
android:id="@+id/lay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="0dp"
android:background="#A0FFFFFF"
android:orientation="horizontal"
android:visibility="invisible" >
<TextView
android:id="@+id/locinfo"
android:layout_width="match_parent"
android:layout_height="60dp"
android:textColor="@color/cherniy"
android:textSize="20sp"
android:visibility="visible" />
</LinearLayout>
</RelativeLayout>
i istnieje ImageButton
button = (ImageButton) findViewById(R.id.imageButton1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (bIcon == false) {
button.setImageResource(R.drawable.plus_yellow);
m = myMap.addMarker(new MarkerOptions().position(myMap.getCameraPosition().target).draggable(true));
LinearLayout linLayout = (LinearLayout)findViewById(R.id.lay);
t = (TextView)findViewById(R.id.locinfo);
linLayout.setVisibility(View.VISIBLE);
t.setVisibility(View.VISIBLE);
bIcon = true;
}
else {
button.setImageResource(R.drawable.plus_grey);
m.remove();
LinearLayout linLayout = (LinearLayout)findViewById(R.id.lay);
t.setVisibility(View.INVISIBLE);
linLayout.setVisibility(View.INVISIBLE);
bIcon = false;
}
}
});
chcę programowo dodać
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams((w*2)/3, LayoutParams.WRAP_CONTENT);
gdzie w
display = getWindowManager().getDefaultDisplay();
@SuppressWarnings("deprecation")
w = display.getWidth();
Ale kiedy ja lubię tego
button.setImageResource(R.drawable.plus_yellow);
m = myMap.addMarker(new MarkerOptions().position(myMap.getCameraPosition().target).draggable(true));
LinearLayout linLayout = (LinearLayout)findViewById(R.id.lay);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams((w*2)/3, LayoutParams.WRAP_CONTENT);
linLayout.setLayoutParams(lp);
t = (TextView)findViewById(R.id.locinfo);
linLayout.setVisibility(View.VISIBLE);
t.setVisibility(View.VISIBLE);
bIcon = true;
Moja aplikacja ulega awarii. Czy możesz powiedzieć, jak programowo tworzyć z moimi parametrami (związanymi z szerokością i wysokością ekranu urządzenia)? Przyjmę wszelkie sugestie. Dziękuję Ci.
Dziękuję. Co potrzebujesz –
możesz umieścić import? Wiem, że to "viewgroup", ale proszę put = :) – delive