Mein Hauptlayout main.xml enthält einfach zwei LinearLayouts:
LinearLayout
hostet ein VideoView
und ein Button
,LinearLayout
hostet ein EditText
, und dieses LinearLayout
hat den Wert Visibility auf " GONE "(Android:visibility="gone"
)wie unten:
<LinearLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:layout_height="fill_parent"
Android:layout_width="fill_parent"
Android:orientation="vertical"
>
<LinearLayout
Android:id="@+id/first_ll"
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:orientation="horizontal"
>
<VideoView
Android:id="@+id/my_video"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_weight="9"
/>
<Button
Android:id="@+id/my_btn"
Android:layout_width="30dip"
Android:layout_height="30dip"
Android:layout_gravity="right|bottom"
Android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
Android:id="@+id/second_ll"
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:paddingTop="2dip"
Android:visibility="gone"
>
<EditText
Android:id="@+id/edit_text_field"
Android:layout_height="40dip"
Android:layout_width="fill_parent"
Android:layout_weight="5"
Android:layout_gravity="center_vertical"
/>
</LinearLayout>
</LinearLayout>
Ich habe die Funktion erfolgreich implementiert, dass beim Drücken von Button
(mit der ID my_btn) das Feld 2ndLinearLayout
mit EditText
angezeigt wird Folgender Java Code:
LinearLayout secondLL = (LinearLayout) findViewById(R.id.second_ll);
Button myBtn = (Button) findViewById(R.id.my_btn);
myBtn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
int visibility = secondLL.getVisibility();
if(visibility==View.GONE)
secondLL.setVisibility(View.VISIBLE);
}
});
Mit dem obigen Code Java) wird der 2ndLinearLayout
mit EditText
wie nten angehängt dargestellt 1stLinearLayout
was Sinn macht.
ABER , was ich brauche ist: Wenn Button
(id: my_btn) gedrückt wird, wird das 2ndLinearLayout
mit EditText
wird oben angezeigt das 1.LinearLayout
, das wie das 2. aussieht = LinearLayout
mit EditText
steigt vom unteren Bildschirmrand auf, und das 2ndLinearLayout
mit EditText
belegt nur einen Teil des Bildschirm von unten, das ist das 1. LinearLayout, das noch sichtbar ist, wie das folgende Bild zeigt:
Wenn also Button
(id: my_btn) gedrückt wird, wird angezeigt, wie 2ndLinearLayout
mit EditText
oben auf = das 1.LinearLayout
anstatt 2.LinearLayout
anzuhängen 1.LinearLayout
programmatisch?
Verwenden Sie ein FrameLayout mit zwei Kindern. Die beiden Kinder werden überlappt. Dies wird in einem der Tutorials von Android eigentlich ist es kein Hack ...
Hier ist ein Beispiel, in dem eine Textansicht über einer Bildansicht angezeigt wird:
<FrameLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent">
<ImageView
Android:layout_width="fill_parent"
Android:layout_height="fill_parent"
Android:scaleType="center"
Android:src="@drawable/golden_gate" />
<TextView
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_marginBottom="20dip"
Android:layout_gravity="center_horizontal|bottom"
Android:padding="12dip"
Android:background="#AA000000"
Android:textColor="#ffffffff"
Android:text="Golden Gate" />
</FrameLayout>
Die Antwort von Alexandru funktioniert ganz gut. Wie er sagte, ist es wichtig, dass diese "Accessor" -Ansicht als letztes Element hinzugefügt wird. Hier ist ein Code, der den Trick für mich getan hat:
...
...
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<!-- place a FrameLayout (match_parent) as the last child -->
<FrameLayout
Android:id="@+id/icon_frame_container"
Android:layout_width="match_parent"
Android:layout_height="match_parent">
</FrameLayout>
</TabHost>
in Java:
final MaterialDialog materialDialog = (MaterialDialog) dialogInterface;
FrameLayout frameLayout = (FrameLayout) materialDialog
.findViewById(R.id.icon_frame_container);
frameLayout.setOnTouchListener(
new OnSwipeTouchListener(ShowCardActivity.this) {
FrameLayout
ist nicht der bessere Weg, dies zu tun:
Verwenden Sie stattdessen RelativeLayout
. Sie können die Elemente beliebig positionieren. Das Element, das danach kommt, hat den höheren Z-Index als das vorherige (d. H. Es kommt über das vorherige).
Beispiel:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
xmlns:app="http://schemas.Android.com/apk/res-auto"
Android:layout_width="match_parent" Android:layout_height="match_parent">
<ImageView
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:background="@color/colorPrimary"
app:srcCompat="@drawable/ic_information"/>
<TextView
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:text="This is a text."
Android:layout_centerHorizontal="true"
Android:layout_alignParentBottom="true"
Android:layout_margin="8dp"
Android:padding="5dp"
Android:textAppearance="?android:attr/textAppearanceLarge"
Android:background="#A000"
Android:textColor="@Android:color/white"/>
</RelativeLayout>