У меня есть один экран с 4 EditText, как menuName, DishName, Tag и Price.
Мне нужно установить мой тег Edittext сверху (+ 56dip) при нажатии на него. Сейчас он работает нормально.
Когда я нажимаю на Tag EditText, он сдвигается так, как я хочу.
Где я застрял
Сдвиг макета работает нормально, но если я нажму на другой EditText, он также переместится, чего я не хочу. Я просто не прокручиваю экран, когда нажимаю на Tag EditText.
Вот мой код Java.
final View activityRootView = findViewById(R.id.RelativeAdd);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView()
.getHeight() - activityRootView.getHeight();
Log.i("TEST",
"GLOBAL LAYOUT " + activityRootView.getHeight());
Log.i("TEST", "GLOBAL LAYOUT rel"+ relativeLayoutHeight);
if (heightDiff > 100) { // if more than 100 pixels, its
// probably a keyboard...
performScrollingUp();
Log.i("TEsT", "Keyboard visible");
} else {
Log.i("TEsT", "Keyboard not visible");
performScrollingDown();
txtDishTags.setDropDownHeight(ViewGroup.LayoutParams.FILL_PARENT);
}
}
});
protected void performScrollingUp() {
if (!isTagUp) {
txtDishTags.setCursorVisible(true);
txtDishTags.setFocusable(true);
txtDishTags.setFocusableInTouchMode(true);
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(txtDishTags, 0);
firstRelativeLayout.setVisibility(View.GONE);
secondRelativeLayout.setVisibility(View.GONE);
firstLinearLayout.setVisibility(View.GONE);
secondLinearLayout.setVisibility(View.GONE);
rlp = new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT,
android.app.ActionBar.LayoutParams.WRAP_CONTENT);
rlp.addRule(RelativeLayout.BELOW, R.id.tempRelativeLayout);
tagRelativeLayout.setLayoutParams(rlp);
isTagUp = true;
final float scale = getResources().getDisplayMetrics().density;
int width = (int) (60 * scale + 0.5f);
int height = (int) (44 * scale + 0.5f);
rlp2 = new RelativeLayout.LayoutParams(width, height);
rlp2.addRule(RelativeLayout.BELOW, R.id.tempRelativeLayout);
rlp2.setMargins(24, 0, 0, 0);
thirdRelativLayout.setLayoutParams(rlp2);
lbltag.setGravity(Gravity.CENTER);
}
}
XML-код для понимания.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeAdd"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EFEFEF"
android:orientation="vertical">
<ViewStub
android:id="@+id/vsHeader2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inflatedId="@+id/header"
android:layout="@layout/copyofheader" />
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<RelativeLayout
android:id="@+id/myRelativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dip"
android:orientation="vertical" >
<EditText
android:id="@+id/hotelName"
android:layout_width="fill_parent"
android:layout_height="44dip"
android:layout_marginLeft="12dip"
android:layout_marginRight="12dip"
android:background="@drawable/borderforloginedittext"
android:ems="10"
android:hint="Name on menu (optional)"
android:inputType="textCapWords"
android:paddingLeft="70dp"
android:textColor="#333333"
android:textColorHint="#999999"
android:textSize="16sp" >
<requestFocus />
</EditText>
</LinearLayout>
<RelativeLayout
android:id="@+id/firstRelativeLayout"
android:layout_width="60dip"
android:layout_height="44dip"
android:layout_marginLeft="12dip"
android:layout_marginTop="12dip" >
<TextView
android:id="@+id/labelName"
android:layout_width="60dip"
android:layout_height="44dip"
android:gravity="center"
android:text="NAME"
android:textColorHint="#999999"
android:textSize="10sp"
android:visibility="visible" >
</TextView>
</RelativeLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/firstRelativeLayout"
android:layout_marginTop="-2dip"
android:orientation="vertical" >
<EditText
android:id="@+id/dishName"
android:layout_width="fill_parent"
android:layout_height="44dip"
android:layout_marginLeft="12dip"
android:layout_marginRight="12dip"
android:background="@drawable/borderforloginedittext"
android:ems="10"
android:hint="(require)"
android:inputType="textCapWords|textPersonName"
android:paddingLeft="70dp"
android:textColor="#333333"
android:textColorHint="#999999"
android:textSize="16sp" >
</EditText>
</LinearLayout>
<RelativeLayout
android:id="@+id/secondRelativeLayout"
android:layout_width="60dip"
android:layout_height="44dip"
android:layout_below="@+id/firstRelativeLayout"
android:layout_marginLeft="12dip"
android:layout_marginTop="-2dip" >
<TextView
android:id="@+id/labelDish"
android:layout_width="60dip"
android:layout_height="44dip"
android:gravity="center"
android:text="DISH"
android:textColorHint="#999999"
android:textSize="10sp"
android:visibility="visible" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/secondRelativeLayout"
android:layout_marginTop="-2dip"
>
<AutoCompleteTextView
android:id="@+id/txtTags"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="44dip"
android:layout_marginLeft="12dip"
android:layout_marginRight="12dip"
android:background="@drawable/borderforloginedittext"
android:hint="eg: Breakfast, spicy, italian "
android:inputType="textNoSuggestions|textMultiLine"
android:imeOptions="actionNext"
android:paddingLeft="70dip"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:dropDownHeight="fill_parent"
android:dropDownWidth="match_parent"
android:textColor="#333333"
android:singleLine="false"
android:textColorHint="#999999"
android:textSize="16sp" >
</AutoCompleteTextView>
<RelativeLayout
android:id="@+id/progressLayout"
android:layout_width="23dip"
android:layout_height="23dip"
android:layout_alignRight="@+id/txtTags"
android:layout_centerVertical="true"
android:layout_marginRight="4dip"
android:layout_marginTop="10dip"
android:layout_below="@+id/linearLayout2"
android:visibility="gone" >
<ProgressBar
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/thirdRelativeLayout"
android:layout_width="60dip"
android:layout_height="44dip"
android:layout_below="@+id/secondRelativeLayout"
android:layout_marginLeft="12dip"
android:layout_marginTop="-2dip" >
<TextView
android:id="@+id/labeltags"
android:layout_width="60dip"
android:layout_height="44dip"
android:gravity="center"
android:text="TAGS"
android:textColorHint="#999999"
android:textSize="10sp"
android:visibility="visible" >
</TextView>
</RelativeLayout>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout3"
android:layout_marginTop="-2dip"
android:orientation="vertical" >
<EditText
android:id="@+id/menuPrice"
android:layout_width="fill_parent"
android:layout_height="44dip"
android:layout_marginLeft="12dip"
android:layout_marginRight="12dip"
android:background="@drawable/borderforloginedittext"
android:ems="10"
android:hint="(optional) "
android:inputType="number"
android:paddingLeft="70dp"
android:textColor="#333333"
android:textColorHint="#999999"
android:textSize="16sp" >
</EditText>
</LinearLayout>
<RelativeLayout
android:id="@+id/fourthRelativeLayout"
android:layout_width="60dip"
android:layout_height="44dip"
android:layout_below="@+id/linearLayout3"
android:layout_marginLeft="12dip"
android:layout_marginTop="-2dip" >
<TextView
android:id="@+id/labelprice"
android:layout_width="60dip"
android:layout_height="44dip"
android:gravity="center"
android:text="PRICE"
android:textColorHint="#999999"
android:textSize="10sp"
android:visibility="visible" >
</TextView>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/fourthRelativeLayout"
android:layout_marginTop="5dip" >
<Button
android:id="@+id/btnAddSecondaryHotel"
android:layout_width="match_parent"
android:layout_height="44dip"
android:layout_marginLeft="12dip"
android:layout_marginRight="12dip"
android:layout_marginTop="12dip"
android:layout_weight="0.5"
android:background="@color/disabledButtonColor"
android:text="Let's go rate this dish!"
android:textColor="@color/white"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
<ImageView
android:id="@+id/imageView1"
android:layout_width="57dip"
android:layout_height="57dip"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dip"
android:layout_marginTop="100dip"
android:src="@drawable/dishoomit" />
Я стараюсь, но ничего не получаю. Пожалуйста, дайте мне любую ссылку или подсказку.